Skip to main content
Source Link
Kaz
  • 3.7k
  • 1
  • 21
  • 32

The probable reason for this is that this keeps the C++ language implementable in environments where the object file and linkage model does not support the merging of multiple definitions from multiple object files.

A class declaration (called a declaration for good reasons) gets pulled into multiple translation units. If the declaration contained definitions for static variables, then you would end up with multiple definitions in multiple translation units (And remember, these names have external linkage.)

That situation is possible, but requires the linker to handle multiple definitions without complaining.

(And note that this conflicts with the One Definition Rule, unless it can be done according to the kind of a symbol or what kind of section it is placed in.)

Post Made Community Wiki by Kaz