What exactly does One Definition Rule in C++ say? The only trustworthy occurence I can find is in The C++ Programming Language, 3rd. ed., P. 9.2.3. Is there any official definition of the rule except that?
Asked
Active
Viewed 1.5k times
51
-
Strongly related: [Does redefining a function from the standard library violate the one-definition rule?](http://stackoverflow.com/q/41670800/514235) – iammilind Jan 16 '17 at 08:51
1 Answers
39
The truth is in the standard (3.2 One definition rule) :
No translation unit shall contain more than one definition of any variable, function, class type, enumeration type or template.
[...]
Every program shall contain exactly one definition of every non-inline function or object that is used in that program; no diagnostic required. The definition can appear explicitly in the program, it can be found in the standard or a user-defined library, or (when appropriate) it is implicitly defined (see 12.1, 12.4 and 12.8). An inline function shall be defined in every translation unit in which it is used.

icecrime
- 74,451
- 13
- 99
- 111
-
3Uh, it's a little more than that. It also concerns multiple translation units. And exceptions to rule (this makes it a bit difficult to talk about it!). Cheers, – Cheers and hth. - Alf Nov 16 '10 at 08:13
-
3Indeed, I would have to quote the whole page, so I went for the essential. – icecrime Nov 16 '10 at 08:14