This code does't compile, and the error information is "undefined reference to `A::a'":
code 1:
#include <iostream>
using namespace std;
class A
{
public:
static const int a=0;
};
int main()
{
cout<<&A::a<<endl;
return 0;
}
But for a non-const static member it compiles:
code 2:
#include <iostream>
using namespace std;
class A
{
public:
static int a;
};
int A::a=0;
int main()
{
cout<<&A::a<<endl;
return 0;
}
Is there just no way of accessing the address of a static const member of a class? If there is, how? And why code 1 does not compile?