Lecture 2 - Slide 5 : 29
Declarations and definitions
It is important to be able to distinguish between
declarations
and
definitions
The C++ Prog. Lang. (3. edition)
:
Page 78
The C++ Prog. Lang. (4. edition)
: Page 152
Declaration
Introduces names - for the benefit of the compiler
Several declarations of the same name are allowed - must agree on the types involved
Definition
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.
The C++ Prog. Lang. (3. edition)
:
ODR. Page 203
A definition is a declaration - a declaration is not necessarily a definition