gcc: Static Definitions

1 
1 13.7.1 Declare _and_ Define Static Members
1 ------------------------------------------
1 
1 When a class has static data members, it is not enough to _declare_ the
1 static member; you must also _define_ it.  For example:
1 
1      class Foo
1      {
1        ...
1        void method();
1        static int bar;
1      };
1 
1  This declaration only establishes that the class 'Foo' has an 'int'
1 named 'Foo::bar', and a member function named 'Foo::method'.  But you
1 still need to define _both_ 'method' and 'bar' elsewhere.  According to
1 the ISO standard, you must supply an initializer in one (and only one)
1 source file, such as:
1 
1      int Foo::bar = 0;
1 
1  Other C++ compilers may not correctly implement the standard behavior.
1 As a result, when you switch to 'g++' from one of these compilers, you
1 may discover that a program that appeared to work correctly in fact does
1 not conform to the standard: 'g++' reports as undefined symbols any
1 static data members that lack definitions.
1