Reputation: 1196
Is it possible to create a function which takes a pointer to another function? How does the prototype of such a function look like?
Upvotes: 4
Views: 394
Reputation: 272507
typedef int (*func)(float, char);
int something_that_takes_a_func(func f) { return f(3.14, 3); }
int foo(float a, char b) { return a - b; }
std::cout << something_that_takes_a_func(&foo) << "\n";
Upvotes: 6
Reputation: 93
void f(int(*Func)())
{
int a = Func();
}
and for a member function:
void f(int(cLass::*Func)())
{
cLass *c = new cLass;
int a = (c->*Func)();
}
Upvotes: 3