Your doSomething
function expects a free function pointer (free function means non-member function). You try to pass a member function pointer to it. This will not work. Why? When you have a free function, say void f(double)
, you can simply call it:
f(3.14);
on the other hand, when you have a member (and non-static) function, to call it you need an object, e.g.:
obj.m(3.14);
and you cannot call a member function without an object. So a member function cannot be used interchangeably with free function, since they are called in different way. Think about the (*f)(i)
call in the doSomething
function - what would be the A
object for multiply
to call upon?
Your design needs rethinking. If you want to share code, maybe you need some class hierarchy and the common code in the base class?