Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: C++
Expertise: All
Mar 29, 1999

Understanding the One Definition Rule

The One Definition Rule (ODR) says that an inline function has to be identically defined in every translation unit in which it is used. Two definitions contained in different translation units are identically defined if and only if they are token-by-token identical, and the tokens have identical meaning in both translation units. For example:
 
  //file fisrt.cpp
inline int C::getVal () { return 5; } 

  //file sec.cpp
typedef int I;
inline I C::getVal () { return 5; } //violation of ODR, I and int are not identical tokens
On the other hand, white spaces and comments are immaterial:
 
  //file fisrt.cpp
inline int C::getVal () { return 5; } 
  //file sec.cpp
inline int C::getVal () { /*complies with the ODR*/
return 5; }
Danny Kalev
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date