Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Nontrivial C++ programs are generally divided into multiple translation units that are later linked together to form an executable. To support such a model, C++ restricts named object definitions to ensure that linking will behave deterministically by requiring a single definition for an object across all translation units. This model is called the One Definition Rule the one-definition rule (ODR), which is defined by the C++ Standard, [basic.def.odr], paragraph 4 [ISO/IEC 14882-2014], as:

...

However, it is possible to violate the ODR of a definition introduced via #include using block language linkage specifications, vendor-specific language extensions, and so on. A more likely scenario for ODR violations is that accidental definitions of differing objects will exist in different translation units.

Do not violate the One Definition Ruleone-definition rule; violations result in undefined behavior.

...