C++中指向函数的指针显示问题(已解决)
#include<iostream> using namespace std;
double add(double,double);
double xx(double,double);
double calculaate(double,double,double (*pf) (double,double));
int main()
{
double i,j,k;
cout<<"please enter two score: ";
while(cin>>i>>j)
{
k=calculaate(i,j,add);
cout<<"New volue is: "<<k<<endl;//1
k=calculaate(i,j,xx);
cout<<"athre volue is: "<<k<<endl;//2
cout<<"please enter two score: ";
}
cout<<"bye! \n";
return 0;
}
double add(double x,double y)
{
return x+y;
}
double xx(double x,double y)
{
return x*y;
}
double calculaate(double a,double b,double (*pf) (double,double))
{
cout<<"New volue is: "<<(*pf)(a,b)<<endl; //这里错了,晕
return (*pf)(a,b);
}
例如我输入40 10
New volue is:50
New volue is:50
New volue is:400
athre volue is:400
为什么不是显示的
New volue is:50
New volue is:400
请高手们帮我把程序改正确,非常感激~!
[[it] 本帖最后由 沿途有鬼 于 2008-7-25 21:49 编辑 [/it]]