c++ - Invalid use of qualified name -
i'm trying following:
#include <iostream> namespace { extern int j; } int main() { int a::j=5; std::cout << a::j; }
but i've error: invalid use of qualified-name ‘a::j’
. please explain why error occurred?
please explain why error occurred?
the language doesn't allow define namespace-scope variables inside functions. definition has either in namespace a
:
namespace { int j = 5; }
or in surrounding (global) namespace:
int a::j = 5;
you can, of course, assign value variable inside function:
int main() { a::j = 5; // ... }
but you'll need definition somewhere, since program doesn't have one.
Comments
Post a Comment