标题:C++中指向函数的指针显示问题(已解决)
只看楼主
沿途有鬼
Rank: 1
等 级:新手上路
帖 子:68
专家分:0
注 册:2008-7-20
 问题点数:0 回复次数:0 
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]]
搜索更多相关主题的帖子: double 指针 函数 add calculaate 
2008-07-25 21:47



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-225263-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.178415 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved