By sharptooth

2010-11-16 08:09:30 8 Comments

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?


@icecrime 2010-11-16 08:11:16

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.

@Cheers and hth. - Alf 2010-11-16 08:13:26

Uh, 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,

@icecrime 2010-11-16 08:14:03

Indeed, I would have to quote the whole page, so I went for the essential.

Related Questions

Sponsored Content

21 Answered Questions

[SOLVED] What is the "-->" operator in C++?

7 Answered Questions

24 Answered Questions

[SOLVED] Why do we need virtual functions in C++?

32 Answered Questions

[SOLVED] What exactly is RESTful programming?

  • 2009-03-22 14:45:39
  • hasen
  • 1599644 View
  • 3839 Score
  • 32 Answer
  • Tags:   http rest definition

18 Answered Questions

[SOLVED] Why should C++ programmers minimize use of 'new'?

35 Answered Questions

1 Answered Questions

[SOLVED] The Definitive C++ Book Guide and List

  • 2008-12-23 05:23:56
  • grepsedawk
  • 2132526 View
  • 4248 Score
  • 1 Answer
  • Tags:   c++ c++-faq

8 Answered Questions

[SOLVED] What is The Rule of Three?

11 Answered Questions

[SOLVED] What does the explicit keyword mean?

Sponsored Content