0
所以基本上我正在做的是從一個函數傳遞一個結構數組到另一個函數。它適用於演出功能,但不適用於最大功能:/我究竟做錯了什麼?表達式必須具有(指針到)函數類型,而使用結構
void show(const ABC & x){
cout<<"{"<<x.n<<",'"<<x.c<<"',{"<<x.a[0]<<","<<x.a[1]<<","<<x.a[2]<<"}}";
}
void show(const ABC arr[], unsigned elements){
for(unsigned i=0; i<elements; i++)
show(arr[i]);
}
以下不起作用
double max(const ABC & x){
double max=x.a[2];
if(x.a[1]>max)
max=x.a[1];
if(x.a[0]>max)
max=x.a[0];
return max;
}
double max(const ABC arr[], unsigned elements){
double max=arr[2].a[3];
for(unsigned i=0; i<elements; i++)
if(max<max(arr[i])){
max=max(arr[i]);
}
return max;
}
今後考慮讓你的編譯器給你明確的錯誤。交叉引用錯誤指向的行也很有幫助。它能幫助我們弄清楚發生了什麼。 –
您可能還想用'const ABC * arr'替換'const ABC arr []'。這兩個語句可能都是相同的,你不應該修改任何引用'arr'的東西,但是如果它給了你某種訪問錯誤,那麼值得一試。 – Ghost2