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

编译是这样的:
#include <stdio.h>
#define M 8
void 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 cast
D:\fiend++\8.7.cpp(10) : error C2197: 'float (__cdecl *)(void)' : too many actual parameters

白衣非少年
浏览 72回答 2
2回答

蛊毒传说

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

ibeautiful

函数指针,请写出参数类型,有些编译器检查较严格。即,将float (*p) (); 改为float (*p)(float *,int);
打开App,查看更多内容
随时随地看视频慕课网APP