You can write a function template as:
template<typename ObjType> void ReceiveFuncPtr (ObjType o, void (ObjType::*pf)(int) ) { (o.*pf)(1); }
This function template automatically selects void foo (int i) .
My previous answer (without deleting it, as it may be useful to others) :
Your problem:
ReceiveFuncPtr(obj, &A::foo);
You can do it:
void (A::*pFun)(int) = &A::foo; // No casting here! ReceiveFuncPtr(obj, pFun); // No casting here!
pFun is a pointer to void A::f(int)
You can also use typedef like:
typedef void (A::*FunDouble)(double); typedef void (A::*FunInt)(int); FunInt pFun = &A::foo;
Nawaz
source share