关于类成员函数中函数指针参数的问题!!
请各位看看,以下代码为啥没法通过编译?
#include <iostream>
#include <math.h>
using namespace std;
class BaseA
{
public:
BaseA()
{
data=0;
}
BaseA(int num)
{
data=num;
}
int Done(int(*Fun)(int))
{
return Fun(data);
}
int Test(int num)
{
return (int)sqrt(num);
}
int DDone()
{
return Done(Test);
}
private:
int data;
};
int main()
{
BaseA First(8);
cout<<First.DDone()<<endl;
return 0;
}
报错是:
--------------------Configuration: grade_twoproject - Win32 Debug--------------------
Compiling...
27.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\grade_twoproject\27.cpp(31) : error C2664: 'Done' : cannot convert parameter 1 from 'int (int)' to 'int (__cdecl *)(int)'
None of the functions with this name in scope match the target type
执行 cl.exe 时出错.
27.obj - 1 error(s), 0 warning(s)
谢谢了!!