|
클래스의 멤버 함수 포인터를 void* 로 형변환하는 방법 중 아래 4 가지와 같이 변수를 통하지 않고
바로 형변환하는 방법이 없을까요?
class TTestClass
{
public:
int Method1(int a,int b,int c)const
{
return (a+b+c);
}
};
방법1:
typedef void (TTestClass::*FuncType)();
FuncType func = (FuncType)&TTestClass::Method1;
*(void**)&func
방법2:
void (TTestClass::*func)() = (void (TTestClass::*)())&TTestClass::Method1;
*(void**)&func
방법3:
union Func2Pointer
{
void (TTestClass::*Func)();
void *VoidPointer;
}fp;
fp.Func = (void (TTestClass::*)())&TTestClass::Method1;
fp.VoidPointer
방법4:
typedef int (__closure *ClosureType)(int a,int b,int c);
union Closure2Pointer
{
ClosureType Closure;
struct{
void *VoidPointer;
void *This;
};
}cp;
TTestClass c1;
cp.Closure = c1.Method1;
cp.VoidPointer
|