C++ 类成员函数作为参数

时间:2021-05-09 21:19:42
 #include <iostream>
using namespace std; typedef int int32_t; struct IMsgBody{
int body;
}; struct Arg{
int arg;
}; class A; typedef int32_t (A::*GetArg_Fun)(IMsgBody *pMsgBody, Arg *stArg); //函数指针 class A
{
public:
A(){}
~A(){}
int32_t GetArg_GameEnd(IMsgBody *pMsgBody,Arg *stArg);
int32_t GetTaskArg(IMsgBody *pMsgBody,Arg *stArg,GetArg_Fun getArg_Fun);
int32_t GetTaskArg(IMsgBody *pMsgBody,Arg *stArg);
}; int32_t main()
{
IMsgBody msgBody;
Arg arg;
msgBody.body = ;
arg.arg = ;
A a;
a.GetTaskArg(&msgBody,&arg);
return ;
} int32_t A::GetArg_GameEnd(IMsgBody *pMsgBody,Arg *stArg)
{
cout<<"pMsgBody:"<<pMsgBody->body<<endl;
cout<<"Arg:"<<stArg->arg<<endl;
return ;
} int32_t A::GetTaskArg(IMsgBody *pMsgBody,Arg *stArg,GetArg_Fun getArg_Fun)
{
int ret = ;
ret = (this->*getArg_Fun)(pMsgBody,stArg);
cout<<"ret = "<<ret<<endl;
return ;
} int32_t A::GetTaskArg(IMsgBody *pMsgBody,Arg *stArg)
{
GetTaskArg(pMsgBody,stArg,&A::GetArg_GameEnd);
return ;
}