P
pembed2003
Hi all,
How come the following won't compile?
#include <iostream>
using std::cout;
using std::endl;
class A{
private:
static A* a;
A(){}
public:
static A* getA(){
if(!a) a = new A;
return a;
}
};
int main(int,char**){
A* p = A::getA(); // ERROR
}
It says something like:
.... in getA():test.cc: undefined reference to 'A::a'
It's a linking error but I don't understand why. Can someone explain to me? Thanks!
How come the following won't compile?
#include <iostream>
using std::cout;
using std::endl;
class A{
private:
static A* a;
A(){}
public:
static A* getA(){
if(!a) a = new A;
return a;
}
};
int main(int,char**){
A* p = A::getA(); // ERROR
}
It says something like:
.... in getA():test.cc: undefined reference to 'A::a'
It's a linking error but I don't understand why. Can someone explain to me? Thanks!