7.4 The One-Definition Rule

Ru-Brd

7.4 The One-Definition Rule

The C++ language definition places some constraints on the redeclaration of various entities. The totality of these constraints is known as the one-definition rule or ODR . The details of this rule are quite complex and span a large variety of situations. Later chapters illustrate the various resulting facets in each applicable context, and you can find a complete description of the ODR in Appendix A. For now, it suffices to remember the following ODR basics:

  • Noninline functions and member functions, as well as global variables and static data members should be defined only once across the whole program .

  • Class types (including structs and unions) and inline functions should be defined at most once per translation unit , and all these definitions should be identical.

A translation unit is what results from preprocessing a source file; that is, it includes the contents named by #include directives.

In the remainder of this book, linkable entity means one of the following: a noninline function or member function, a global variable or a static data member, including any such things generated from a template.

Ru-Brd


C++ Templates
C++ Templates: The Complete Guide
ISBN: 0201734842
EAN: 2147483647
Year: 2002
Pages: 185

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net