const variable can be initialized with constant values (constant expressions).
At compile time, i + 1 not a constant expression.
Fwiw even
const int n = i;
will give you an error, because even if declared as const , i cannot be used as a constant expression, which will be used as an initializer for another const .
const variables are protectors as a constant expression if they are initialized by constant expressions. Therefore, it is allowed.
source share