Because you must explicitly define your class's static data
members.
Fred.h:
class Fred {
public:
Fred();
...
private:
int i_;
static int j_;
};
Fred.cpp (or
Fred.C or whatever):
Fred::Fred()
: i_(10) // OK: you can (and should) initialize member data this way
, j_(42) // Error: you cannot initialize static member data like this
{
...
}
// You must define static data members this way:
int Fred::j_ = 42;
Note: in some cases, the definition of
Fred::j_ might not contain the
= initializer part. See
here and
here for details.