Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) function

 

There are multiple classes with the name 'function':

  1. Boost Boost.Function: the Boost library
  2. Boost boost::function: the function wrapper in the Boost.Function library
  3. C++11 std::function: the function wrapper in the C++11 STL

 

A function (in general) is a callable 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).

 

There are multiple types of 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>

//SayHello is a function that takes no arguments and returns nothing
void SayHello()
{
  std::cout << "Hello world" << std::endl;
}

//main is a special function: this form of main takes no arguments
//and returns the program's error code
int main()
{
  SayHello();
}

 

A function that accompanies a class (and is non-friend) is called a free function.

 

 

 

 

 

Advice

 

 

 

 

 

 

External links

 

 

 

 

 

 

Reference

 

  1. Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 13.7. Advice. page 387: '[33] Assume that every exception that can be thrown by a function will be thrown'

 

 

 

 

 

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

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict