Go back to Richel Bilderbeek's homepage.

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

 

 

 

(C++) function

 

A function is a piece of code that performs a specific general task with as little information as possible ( Why would you want this? Go to this page to view the purpose of using functions).

 

A function declaration states what a function needs and returns. A function definition states how a function uses its arguments and calculates what to return.

 

 

 

#include <iostream>

 

void SayHello()

{

  std::cout << "Hello world" << std::endl;

}

 

int main()

{

  SayHello();

}

 

 

Note that main is a special function.

 

If the data type the function works on, consider making it a template function.

 

Consider using proper function design.

 

Avoid long functions [0].

 

 

 

 

 

External links

* WikiPedia's page about functions

 

 

 

 

 

References

[0]         Herb Sutter, Andrei Alexandrescu. C++ coding standards: 101 rules, guidelines, and best practices. ISBN: 0-32-111358-6. Item 20: 'Avoid long functions. Avoid deep nesting'.

 

 

 

 

 

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

Go back to Richel Bilderbeek's homepage.