Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

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



Building the Right Environment to Support AI, Machine Learning and Deep Learning

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.



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