为了账号安全,请及时绑定邮箱和手机立即绑定

以下是什么意思啊?我看不太懂.究竟那里错了?

以下是什么意思啊?我看不太懂.究竟那里错了?

C
白衣非少年 2023-01-03 15:07:02
编译是这样的:#include <stdio.h>#define M 8void main (){float sumf,sump;float a[M]={11,2,-3,4.5,5,69,7,80};float (*p) ();float max (float a[],int n);p=max;sump=(*p) (a,M);sumf=max(a,M);printf ("sump=%.2f\n",sump);printf ("sumf=%.2f\n",sumf);}float max (float a[],int n){int k;float s;s=a[0];for (k=0;k<n;k++)if (s<a[k])s=a[k];return s;}是从书上照打下去的但编译时却有问题:D:\fiend++\8.7.cpp(9) : error C2440: '=' : cannot convert from 'float (__cdecl *)(float [],int)' to 'float (__cdecl *)(void)'This conversion requires a reinterpret_cast, a C-style cast or function-style castD:\fiend++\8.7.cpp(10) : error C2197: 'float (__cdecl *)(void)' : too many actual parameters
查看完整描述

2 回答

?
蛊毒传说

TA贡献1895条经验 获得超3个赞

指针函数参数的定义与它所指向的函数的参数定义不一致,可以尝试改为:float (*p) (float a[],int n);

查看完整回答
反对 回复 2023-01-06
?
ibeautiful

TA贡献1993条经验 获得超5个赞

函数指针,请写出参数类型,有些编译器检查较严格。
即,将float (*p) (); 改为float (*p)(float *,int);

查看完整回答
反对 回复 2023-01-06
  • 2 回答
  • 0 关注
  • 71 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信