Function Pointer - in C++

In C++

A C++ typical use of "pointers to functions" is for passing a function as an argument to another function, since these cannot be passed dereferenced:

// Pointer to functions // compile: g++ -g functPointCpp.cc -o functPointCpp #include using namespace std; int add(int first, int second) { return first + second; } int subtract(int first, int second) { return first - second; } int operation(int first, int second, int (*functocall)(int, int)) { return (*functocall)(first, second); } int main { int a, b; int (*plus)(int, int) = add; a = operation(7, 5, plus); b = operation(20, a, subtract); cout << "a = " << a << " and b = " << b << endl; return 0; }

Read more about this topic:  Function Pointer