BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / cpp / #86272同步于 2015/4/1
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖

expected ‘double (*)(double, void *)’ but argument is of

sharonyue
2015/4/1镜像同步2 回复
d 附件(45.2KB) integral.rar 大家好,我最近在做积分。从国外下载了一个高斯积分的公式。本来这个东西需要在外面定义被积分的函数,就是我评论掉的f函数,但是我想把它移到主函数里面来。会报错。这个应该怎么处理呢? //double f(double x, void* data) //{ // return pow(3.0,x); //} int main(int argc, char* argv[]) { /* numerical approximation of integral */ double approx; /* true value of int(sin(x), x=0..Pi) = 2.0*/ double exact = 1.8205; /* approximation error */ double error; int i; double x; double f = pow(3.0,x); printf("Numerical Approximation of int(sin(x), x=0..Pi) by Gauss-Legendre Quadrature:\n"); for (i=2;i<=128;i++) { approx = gauss_legendre(i,f,NULL,0,1); error = approx-exact; printf("n = %4d: error = %.15g\n",i,FABS(error)); } return 0; } 错误提示: example.c: In function ‘main’: example.c:40:3: error: incompatible type for argument 2 of ‘gauss_legendre’ approx = gauss_legendre(i,f,NULL,0,1); ^ In file included from example.c:5:0: gauss_legendre.c:233:8: note: expected ‘double (*)(double, void *)’ but argument is of type ‘double’ double gauss_legendre(int n, double (*f)(double,void*), void* data, double a, double b) ^ make: *** [Make/linux64GccDPOpt/example.o] Error 1
订阅后,新回复会通过你的通知中心匿名送达。
2 条回复
BTup机器人#1 · 2015/4/1
gauss_legendre()第二个参数要求是原型如下的函数,就是那个f函数 double f(double, void *) 【 在 sharonyue 的大作中提到: 】 : d[upload=1][/upload] : 大家好,我最近在做积分。从国外下载了一个高斯积分的公式。本来这个东西需要在外面定义被积分的函数,就是我评论掉的f函数,但是我想把它移到主函数里面来。会报错。这个应该怎么处理呢? : [code=c] : ...................
sharonyue机器人#2 · 2015/4/2
【 在 BTup 的大作中提到: 】 : gauss_legendre()第二个参数要求是原型如下的函数,就是那个f函数 : double f(double, void *) xiele谢了 昨天搞半天没搞明白,后来索性自己写了个高斯勒让德函数。