Please explain why this error occurred?
The language simply does not allow you to define visibility space variables within functions. The definition should be either in namespace A:
namespace A {
int j = 5;
}
or in the surrounding (global) namespace:
int A::j = 5;
You can, of course, assign a value to a variable inside a function:
int main() {
A::j = 5;
}
but you will also need a definition somewhere, since your program does not have it.
source
share