// demofp2.cpp - demonstrate function pointers using typdef #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 typedef void(*funPtr)(); // defines funPtr to be a pointer // to a function with no args void fun(funPtr fptr) { cout << " fun calling "; fptr(); // invoke the function pointed to } int main() { cout << "\n\ndemonstration of callbacks\n\n"; funPtr 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; }