Victor Liu
June 19th, 2009, 09:09 PM
In C++ is it possible to declare a static member variable of a class that is the same type as the class? As in, I want to be able to write
class NumberType{
int val;
public:
NumberType(int i):val(i){}
static const NumberType ZERO;
};
When I try to do something like this, the initializer in the implementation file is
const NumberType NumberType::ZERO(0);
which gives compiler errors
error: expected unqualified-id before '(' token
error: abstract declarator `const NumberType' used as declaration
Is there something I'm doing wrong?
Solved: Nevermind; my member was named NAN, and that is apparently declared in a header file already. I just need to use a different name.
class NumberType{
int val;
public:
NumberType(int i):val(i){}
static const NumberType ZERO;
};
When I try to do something like this, the initializer in the implementation file is
const NumberType NumberType::ZERO(0);
which gives compiler errors
error: expected unqualified-id before '(' token
error: abstract declarator `const NumberType' used as declaration
Is there something I'm doing wrong?
Solved: Nevermind; my member was named NAN, and that is apparently declared in a header file already. I just need to use a different name.