c++ - How to access the address of a static const member of a class? -
this code does't compile, , error information "undefined reference `a::a'":
code 1:
#include <iostream> using namespace std; class { public: static const int a=0; }; int main() { cout<<&a::a<<endl; return 0; }
but non-const static member compiles:
code 2:
#include <iostream> using namespace std; class { public: static int a; }; int a::a=0; int main() { cout<<&a::a<<endl; return 0; }
is there no way of accessing address of static const member of class? if there is, how? , why code 1 not compile?
put
const int a::a;
in source file, otherwise compiler doesn't generate address a. note value not repeated here.
Comments
Post a Comment