編譯是這樣的:#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;}是從書(shū)上照打下去的但編譯時(shí)卻有問(wèn)題: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 回答

蠱毒傳說(shuō)
TA貢獻(xiàn)1895條經(jīng)驗(yàn) 獲得超3個(gè)贊
指針函數(shù)參數(shù)的定義與它所指向的函數(shù)的參數(shù)定義不一致,可以嘗試改為:float (*p) (float a[],int n);

ibeautiful
TA貢獻(xiàn)1993條經(jīng)驗(yàn) 獲得超6個(gè)贊
函數(shù)指針,請(qǐng)寫(xiě)出參數(shù)類(lèi)型,有些編譯器檢查較嚴(yán)格。
即,將float (*p) (); 改為float (*p)(float *,int);
- 2 回答
- 0 關(guān)注
- 136 瀏覽
添加回答
舉報(bào)
0/150
提交
取消