C++类成员函数如何赋值给函数指针

2025-05-06 03:50:53
推荐回答(3个)
回答1:

完善了一下。

#include
using namespace std;
class Ca{
public:
int max(int a,int b)
{
return a>b?a:b;
}
};
int (Ca::*p)(int,int);
int main()
{
p=&Ca::max;
Ca a;
cout<<(a.*p)(2,3);
system("pause");
return 0;
}

回答2:

把void (*Paint_MainWnd)();换成这个typedef void (*FunT)();

然后FunT Paint_MainWnd = a.PaintFramework();

回答3:

定义成员函数指针类型