Declarations and definitions
It is important to be able to distinguish between declarations and definitions
- Introduces names - for the benefit of the compiler
- Several declarations of the same name are allowed - must agree on the types involved
- A declaration that also defines an entity
- A location in memory
- A function with a body
- There must be precisely one definition of a named entity
- The one-definition-rule (ODR) relaxes this a bit - for the benefit of multiple includes:
- A class, inline function, or template may be defined more than once
- if they appear in different translation units
- if they are token-for-token identical
Illustration of declarations and definitions - everything is fine.
Illustration of declarations and definitions - several problems.
A definition is a declaration - a declaration is not necessarily a definition