Code Yarns ‍👨‍💻
Tech BlogPersonal 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