Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) definition

 

'A definition provides a unique description of an entity (for example, type, instance, function) within a program' [1].

 

There are two types of definitions:

  1. A variable definition is a variable declaration with specifying an initial value.
  2. A function definition is a function declaration with specifying the function body.

 

 

 

 

 

Variable definition

 

A variable definition is a variable declaration with specifying an initial value.

 

int main()
{
  //Declaration of 'declared_value', initial value undefined
  int declared_value;
  //Definition of variable 'value'
  const int value = 3;
}

 

Postpone variable definitions as long as possible [2].

 

 

 

 

 

Function definition

 

A function definition is a function declaration with specifying the function body.

 

//A function declaration
double calculateZogsmurk(const std::vector<double>& myVector)

//A function definition
double calculateSum(const std::vector<double>& myVector)
{
  double sum = 0.0;
  const int size = myVector.size();
  for (int i=0; i!=size; ++i)
  {
    sum+=myVector[i];
  }
  return sum;
}

 

 

 

 

 

References

 

  1. John Lakos. Large-Scale C++ Software Design. 1996. ISBN: 0-201-63362-0. Chapter 1.1.1
  2. Scott Meyers. Effective C++ (3rd edition). ISBN: 0-321-33487-6. Item 26: 'Postpone variable definitions as long as possible'.

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict