class AA
{
public:
int GetAA(int x)
{
return x;
}
};
class BB
{
public:
void GetBB()
{
OutputDebugStringA("xx");
}
};
class CC
{
public:
AA _aa;
BB _bb;
template<typename T>
void* Get()
{
return nullptr;
}
template<>
void* Get<AA>()
{
return &_aa;
}
template<>
void* Get<BB>()
{
return &_bb;
}
};
#define CallFunc(type, func, ...) do \
{\
type* p = (type*)cc.Get<type>();\
if (!p)\
{\
break;\
}\
p->func(##__VA_ARGS__);\
} while (0);
#define CallFunc_ret(type, func, ret, ...) do \
{\
type* p = (type*)cc.Get<type>();\
if (!p)\
{\
break;\
}\
ret = p->func(##__VA_ARGS__);\
} while (0);
调用
CC cc;
CallFunc(AA, GetAA, 1);
CallFunc(AA, GetAA, 2);
CallFunc(BB, GetBB);
int ret = -1;
CallFunc_ret(AA, GetAA, ret, 2);