Here is the code,
class A {
public:
static A *get_a()
{
if(_pa == 0)
_pa = new A;
return _pa;
}
private:
static A *_pa = 0; //cannot compile
};
In the above code, if I move _pa
's definition outof the class,
A * A::_pa = 0; //can compile
My problem is, static A *_pa = 0
inside the class body is just a declaration, not a definition, right?
Moreover, is it valid to assign a value to a static
data member inside the class?