Code Yarns β€πŸ‘¨β€πŸ’»
Tech Blog ❖ Personal Blog

C++: One Definition Rule (ODR)

πŸ“… 2010-Oct-26 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ cpp, odr ⬩ πŸ“š Archive

Every C++ programmer is aware of the One Definition Rule (ODR), but in a vague sense: β€œOnly one definition of something is allowed in something.” I was surprised to learn that the ODR stumps not just us mortals, but the architects of C++ itself. More than a decade after the birth of C++, in a 1995 C++ Standards meeting it took the architects 2 entire days to put down this rule to paper! 😊

Attempt 1

Here is a simple breakdown of the ODR:

Attempt 2

Alternatively, we can flip around the definition of the rule and try to understand it from the point-of-view of the entities:

References


Β© 2022 Ashwin Nanjappa β€’ All writing under CC BY-SA license β€’ 🐘 @codeyarns@hachyderm.io β€’ πŸ“§