#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;}
程序编译之后的错误提示:
error C2440: '=' : cannot convert from 'float (__cdecl *)(float [],int)' to 'float (__cdecl *)(void)'
偶已经想爆头了,高手提示一下。
#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;}
程序编译之后的错误提示:
error C2440: '=' : cannot convert from 'float (__cdecl *)(float [],int)' to 'float (__cdecl *)(void)'
偶已经想爆头了,高手提示一下。