标题:求助,关于指针指向函数语法错误问题
取消只看楼主
shanexia
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2013-11-17
结帖率:40%
已结贴  问题点数:20 回复次数:3 
求助,关于指针指向函数语法错误问题
下面是源码:
#include<stdio.h>//一个函数既可以计算抛物线,又可以计算余弦函数,用指针函数实现。
#include<math.h>
double y(double);
double cos(double);
double total(double (*f)(),double min,double max,double step);
int main()
{

total(y,0.0,2.0,0.5);//返回y(x),x=0,0.5,1,1.5,2
printf("cos is:\n");
total(cos,0.0,2.0,0.5);返回cos(x),x=0,0.5,1,1.5,2
return 0;
}
double y(double x)
{
return(2*x*x-x+1);
}
double total(double (*f)(),double min,double max,double step)
{
double a=0,value;
for(a=min;a<=max;a+=step)
{
value=(*f)(a);
printf("%5.2f,%5.4f\n",a,value);
}
return 0;
}
搜索更多相关主题的帖子: include double return 抛物线 
2014-03-03 09:21
shanexia
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2013-11-17
得分:0 
自己顶一下。求大神解答,程序通不过,到底哪里出错了啊
2014-03-03 09:22
shanexia
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2013-11-17
得分:0 
:\vc++6.0\MSDev98\MyProjects\1\1.cpp(9) : error C2664: 'total' : cannot convert parameter 1 from 'double (double)' to 'double (__cdecl *)(void)'
        None of the functions with this name in scope match the target type
E:\vc++6.0\MSDev98\MyProjects\1\1.cpp(11) : error C2664: 'total' : cannot convert parameter 1 from 'double (double)' to 'double (__cdecl *)(void)'
        None of the functions with this name in scope match the target type
E:\vc++6.0\MSDev98\MyProjects\1\1.cpp(23) : error C2197: 'double (__cdecl *)(void)' : too many actual parameters
执行 cl.exe 时出错.

1.obj - 1 error(s), 0 warning(s)
语法错误。
2014-03-03 10:21
shanexia
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2013-11-17
得分:0 
我是照书上敲的代码
2014-03-03 10:23



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




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

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