Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
This page is about two different functions:
function (general): a piece of callable code
boost::function: the Boost.Function library
function (general)
A function 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).
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> |
A function that accompanies a class (and is non-friend) is called a free function.
Consider using proper function design. Avoid writing long functions [1-2].
boost::function: the Boost.Function library
boost::function is part of the Boost.Function library for working with functions in general, including member functions.
boost::function example 1
Below are two pieces of near-identical code, the first using function pointers to global functions, the second using boost::function.
#include <algorithm> |
#include <algorithm> |
Possible screen output:
1 |
boost::function example 2
#include <iostream> |
Screen output:
Hello! |
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.