Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) definition

 

'A definition of a function tells the compiler how the function works. It shows what instructions are executed for the function.' [3]

 

'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;
}

 

 

 

 

 

 

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;
}

 

 

 

 

 

Advice

 

 

 

 

 

 

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'.
  3. Joint Strike Fighter Air Vehicle C++ Coding Standards for the System Development and Demonstration Program. Document Number 2RDU00001 Rev C. December 2005. 4.3.15: 'A definition of a function tells the compiler how the function works. It shows what instructions are executed for the function.'
  4. Paul Deitel, Harvey Deitel. C++11 for programmers (2nd edition). 2014. ISBN: 978-0-13-343985-4. Chapter 3.1, Common Programming Error 3.1. page 39: 'Forgetting the semicolon at the end of a class definition is a syntax error.'

 

 

 

 

 

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

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict