[求救]报错:没有找到接受“void”类型的右操作数的运算符(或没有可接受的转换)
本帖最后由 achang21 于 2010-08-25 21:27:05 编辑 我是c++初学者,写了一段学习 函数指针的代码,运行报错,希望大家能帮我,非常感谢。
代码如下:
#include "stdafx.h"
double bery(int);
double pum(int);
void estimate(int lines,double (*pf)(int));
int _tmain(int argc, _TCHAR* argv[])
{
using namespace std;
int a;
cin>>a;
cout<<estimate(a,bery)<<endl;
cout<<estimate(a,pum)<<endl;
return 0;
}
double bery(int a)
{
return a*5;
}
double pum(int a)
{
return a+5;
}
void estimate(int lines,double(*pf)(int))
{
using namespace std;
cout<<lines<<"will take"<<endl;
cout<<(*pf)(lines)<<" check!"<<endl;
}
说明:iostream 文件已经在stdafx.h包含。
运行报错:error C2679: 二进制“<<”: 没有找到接受“void”类型的右操作数的运算符(或没有可接受的转换)
大家帮我看下。
[解决办法]
cin>>a;
estimate(a,bery);
estimate(a,pum);
return 0;
[解决办法]
estimate函数返回void,而cout<<void是不行的。
[解决办法]
可以让estimate函数返回某个类型,然后用cout输出这个返回值,但是好像没什么必要。
既然estimate函数里面已经输出了,main里面就直接调用他一下就可以了,不必再cout了