// demofp1.cpp - demonstrate function pointers #include using namespace std; void fun1() { cout << "fun1()\n"; } void fun2() { cout << "fun2()\n"; } void fun3() { cout << "fun3()\n"; } // define a function taking a function pointer argument void fun(void(*fptr)()) { cout << " fun calling "; (*fptr)(); // invoke the function pointed to } int main() { cout << "\n\ndemonstration of callbacks\n\n"; void (*callback[3])(); // declare an array of function pointers // with the same signatures as fun1,... callback[0] = fun1; callback[1] = fun2; callback[2] = fun3; for (int i=0; i<3; i++) fun(callback[i]); // pass the function pointer argument cout << "\n\n"; return 0; }