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

//main.cpp
void (*Paint_MainWnd)() ;
...
class A
{
...
void PaintFramework() ;
} ;
A a ;
Paint_MainWnd = a.PaintFramework() ;
VS 2008 编译时报错:
错误 10 error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
错误 14 error C2373: “Paint_MainWnd”: 重定义;不同的类型修饰符
错误 15 error C3867: “CSDKEasy::PaintFramework”: 函数调用缺少参数列表;请用“&CSDKEasy::PaintFramework”创建指向成员的指针。

第1个回答  2015-08-16
完善了一下。

#include<iostream>
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个回答  推荐于2017-06-24
把void (*Paint_MainWnd)();换成这个typedef void (*FunT)();

然后FunT Paint_MainWnd = a.PaintFramework();

本回答被网友采纳
第3个回答  2015-08-15
定义成员函数指针类型
相似回答