Http://www.parashift.com/c++-faq-lite/link-errs-static-data-mems.html
Because static data members must is explicitly defined in exactly one compilation. If you are didn ' t do this and you'll probably get a "undefined external" linker error. For example:
Fred.h
class Fred {public
:
...
Private:
static int j_; Declares static data member Fred::j_ ...
};
The linker would holler at your ("Fred::j_ is not defined") unless your define (as opposed to merely declare) fred::j_ in ( Exactly) one of your source files:
Fred.cpp
#include "Fred.h"
int fred::j_ = some_expression_evaluating_to_an_int;
Alternatively, if you wish the implicit 0 value for static ints:
//int fred::j_;
The usual place to define static data members of class Fred is file Fred.cpp (or fred.c or whatever source file Exten Sion use).
Note:in some cases, you can add = initializer; To the declaration of Class-scope static declarations, however if your ever use the ' data ', you still need to explicit Ly define it in exactly one compilation. In this case you don ' t include a = initializer in the definition. A separate FAQ covers this topic.