TITLE: The One-Definition Rule (Newsgroups: comp.lang.c++.moderated, 27 Feb 98) KIM: "Jaewoo Kim" >I'm still new to C++, so my question could be out-dated. CLAMAGE: clamage@Eng.Sun.COM (Steve Clamage) Not at all. The ODR is fundamental to C++. KIM: >What does the One Definition Rule mean in C++? >Can I find the precise definiton and impact in CD2? >I'm interested in the semantic impact on C++. CLAMAGE: It takes two full pages in the draft to express the ODR. Very much over-simplified, it makes three kinds of statements: 1. In any one translation unit, a template, type, function, or object can have no more than one definition. (Some of these can have any number of declarations. A definition provides an instance.) 2. In the entire program, an object or non-inline function cannot have more than one definition; if an object or function is used, it must have exactly one definition. (You can declare an object or function that is never used, in which case you don't have to provide a definition. In no event can there be more than one definition.) 3. Some things, like types, templates, and extern inline functions, can be defined in more than one translation unit. For a given entity, each definition must be the same. (Non-extern objects and functions in different translation units are different entities, even if their names and types are the same.) Some violations of the ODR must be diagnosed by the compiler. Other violations, particularly those that span translation units, are not required to be diagnosed. I've glossed over some important points like "used" and "the same", and exactly what constitutes a definition. The full text of the ODR is section 3.2 "One definition rule" in the draft standard.