One Definition Rule (ODR)¶
ODR is a rule for C++ programs that forbids declarations of the entities with same name but by different C++ code. Better/exact description is out of the scope of this document, please visit the links below for details if needed.
As a brief overview you can’t do things like:
// Boo.hpp
class Foo {
int a;
};
// Bar.hpp
class Foo {
double a; // ODR violation, defined differently!
};
Though this code looks trivial and violation is obvious, there are scenarios when it’s no so easy to detect such kind of errors, e.g. see examples from Library Symbols section.
See also