今天看《inside the c++ object model》时想到了一个把类成员函数指针转化为普通函数指针的办法
这在把类成员函数作线程函数的场合应该有用,这个办法仅能转化非虚函数:
class A
{
public:
void f(){printf("aa");}
};
int _tmain(int argc, _TCHAR* argv[])
{
A a;
typedef void (A::*PCF)();
PCF pcf = &A::f;
unsigned * ppcf= (unsigned *)(&pcf);//通过中间变量转化两个指针
typedef void (*PF)(A*);
PF pf = (PF)(*ppcf);
(*pf)(&a);
int c;
scanf("%d",&c);
return 0;
}