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

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -