// demofp2.cpp - demonstrate function pointers using typdef #include void fun1() { std::cout << "fun1()\n"; } void fun2() { std::cout << "fun2()\n"; } void fun3() { std::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) { std::cout << " fun calling "; fptr(); // invoke the function pointed to } void main() { std::cout << "\n\n Demonstrate 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 std::cout << "\n"; }