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

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -