直接调用类的成员函数(不创建对象)
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
class AAA
{
public:
void callback()
{
printf("callback\r\n");
};
};
typedef void (__cdecl *PF)();
void test(PF pfunc)
{
(*pfunc)();
};
template <typename T1, typename T2> void nb_cast(T1& t1, T2 t2)
{
union
{
T1 func1;
T2 func2;
} ut;
ut.func2 = t2;
t1 = ut.func1;
};
int _tmain(int argc, _TCHAR* argv[])
{
PF pf;
nb_cast(pf, &AAA::callback);
test(pf);
system("pause");
return 0;
}