TITLE: why initialize static data outside class declaration (Newsgroups: comp.lang.c++, 18 Jul 98) NATALIE: Ron Natalie > This still doesn't do anything to explain why C++ requires > > class foo { > static int x; > }; > > foo::x = 1; > > in lieu of > > class foo { > static int x = 1; > }; STRUSTRUP: bs@research.att.com (Bjarne Stroustrup) As a result of #include, class definitions often/typically appear in many translation units. Had in-class initializers been allowed the implementor would have had to face a few problems: Where should initialization code be generated? Is the value used as initializer the same in all translation units? These problems could be dealt with, but requiring a single unique definition (as for every other statically allocated object) simplifies matters considerably. Standard C++ allows one very limited special case of in-class initialization: class X { static const int max = 7; // ... int v[max]; // ... }; See "The C++ Programming Language (3rd edition) for details.