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