Lecture overview -- Keyboard shortcut: 'u'  Previous page: Structs in C++ -- Keyboard shortcut: 'p'  Next page: The structure of a declaration -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Help page about these notes  Alphabetic index  Course home  Lecture 2 - Page 5 : 42
Notes about C++
Basic facilities
Declarations and definitions

It is important to be able to distinguish between declarations and definitions

  • The C++ Programming Language: Page 78
 

  • Declaration

    • Introduces names and types - 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

y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/declarations-definitions/decl-def.ccIllustration of declarations and definitions - everything is fine.


y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/declarations-definitions/decl-def-problems.ccIllustration of declarations and definitions - several problems.


  • The C++ Programming Language: ODR. Page 203
 

A definition is a declaration - a declaration is not necessarily a definition