类MFC实现无参数函数指针保存有参数函数指针

#include <iostream>

using namespace std;
class A;
typedef void ( A:: * PFN)(void);

class A
{
public:
void FunA(int num)
{
cout<<"FunA in A num ="<<num<<endl;
}
};

union MM
{
PFN pfn;
void (A:: * pfn_vi)(int);
};
int main(void)
{
PFN pfn;
A a;
pfn =(PFN)(a.FunA);
MM mm;
mm.pfn=pfn;
(a.*mm.pfn_vi)(3);
return 0;
}

//输出结果:FunA in A num =3

你可能感兴趣的:(函数指针)