Interview Question

What is the One Definition Rule (ODR)?

The ODR governs legal definitions across translation units.

💡 Concept ✅ Quick Revision 🧠 C++

Answer

The One Definition Rule controls how many definitions of entities may appear in a C++ program. • A definable item generally has at most one definition in a translation unit. • Some entities such as inline functions and templates may have equivalent definitions in multiple translation units. • Violating an ODR rule can make a program ill-formed, sometimes with no diagnostic required.

💡 C++ Example

// math.hpp inline int square(int value) { return value * value; }

⚡ Quick Revision

The ODR governs legal definitions across translation units.