Possible Duplicate:
Cast pointer to member function to normal pointer
there are some codes
class TT {
public:
void set();
void par1(int, int);
void par2(double, double);
};
typedef void(*Ptr1)(TT &, int, int);
typedef void(*Ptr2)(TT &, double, double);
void hello(Ptr1, Ptr2){...}
void TT::set()
{
hello(&TT::par1, &TT::par2);
}
and the error shows:
error C2664: 'hello' : cannot convert parameter 1 from 'void (__thiscall TT::* )(int,int)' to 'Ptr1'
please tell me how to solve this problem?
You want to do this
typedef void(TT::*Ptr1)(int, int);typedef void(TT::*Ptr2)(double, double);And fix hello function to take a pointer to
thissince you need the this pointer to call a function on an object.Check this post out for more information on member function pointers.