It will not compile because foo1 has a signature:
void foo1(int a);
which you are trying to insert in a pointer to:
void F()
Function signatures do not match. The fact that foo1 has a default parameter does not change the signature of the function (it can still be int ).
More general solution
I would say forget about templates, they limit you here.
Personally, I solve the callback problem using function objects with argument binding. This can be done using the boost :: function library and binding default arguments using boost :: bind (or std::bind1st and std::bind2nd ).
These accelerator libraries are also built into the new C ++ 11 standard, like std::function , and std::bind .
It's worth taking a look at this, as it allows you to do very nice things, for example, provide default arguments for functions or use member functions of a class as callbacks.
There are many code examples on the sites I linked to everyone, and boost links have tutorials.
source share