Please give a simple example.

    1 answer 1

    Here is the simplest example. It is necessary to pass a function pointer as a parameter. The topic of function pointers is quite complex. You can read about it in K & R, it is described in sufficient detail there.

    #include <iostream> using namespace std; int f1 (int a) { cout << "f1: " << a << endl; return a*2; } void f2 (int (*ff) (int), int a) { int i = ff (a); cout << "f2: " << i << endl; } int main() { f2(f1, 5); return 0; } 

    g ++ test.cpp -o prog

    ./prog

    f1: 5

    f2: 10

    • mikillskegg thank you very much, now I understand everything) - Jonny-ice