Definitions of Static Const Data Members
In pre-standard C++, all static data members required a definition outside of their class. However, during the C++ standardization process it was decided to lift this requirement for static const integral members. The intent was to allow uses such as:
struct C { static const int N = 10; }; char data; // N "used" without out-of-class definitionwithout a namespace scope definition for N
.
Nevertheless, the wording of the 1998 C++ standard still required a definition if the member was used in the program. This included the member appearing anywhere except as the operand to sizeof or typeid, effectively making the above ill-formed.
This was identified as a defect, and the wording was adjusted to allow such a member to appear anywhere a constant expression is required, without requiring an out-of-class definition. This includes array bounds, case expressions, static member initializers, and nontype template arguments.
struct C { static const int N = 10; static const int U = N; // Legal per C++03 }; char data; // Legal per C++03 templateHowever, using a static const integral member anywhere except where an integral constant-expression is required requires a definition:
struct C { static const int N = 10; }; int main { int i = C::N; // ill-formed, definition of C::N required }This requirement has been relaxed in the current C++ standard, C++11.
Read more about this topic: One Definition Rule
Famous quotes containing the words definitions of, definitions, data and/or members:
“What I do not like about our definitions of genius is that there is in them nothing of the day of judgment, nothing of resounding through eternity and nothing of the footsteps of the Almighty.”
—G.C. (Georg Christoph)
“The loosening, for some people, of rigid role definitions for men and women has shown that dads can be great at calming babiesif they take the time and make the effort to learn how. Its that time and effort that not only teaches the dad how to calm the babies, but also turns him into a parent, just as the time and effort the mother puts into the babies turns her into a parent.”
—Pamela Patrick Novotny (20th century)
“Mental health data from the 1950s on middle-aged women showed them to be a particularly distressed group, vulnerable to depression and feelings of uselessness. This isnt surprising. If society tells you that your main role is to be attractive to men and you are getting crows feet, and to be a mother to children and yours are leaving home, no wonder you are distressed.”
—Grace Baruch (20th century)
“...wasting the energies of the race by neglecting to develop the intelligence of the members to whom its most precious resources must be entrusted, already seems a childish absurdity.”
—Anna Eugenia Morgan (18451909)