![]() |
#2
rjsp2020-11-30 08:24
|
total.maker=a->maker;
错误信息为:
[Error] invalid array assignment
如何修改,代码如下:

#include<iostream>
using namespace std;
struct box{
char maker[40];
float height;
float width;
float length;
float volume;
};
void function(box a){
cout<<a.maker<<endl<<a.height<<endl<<a.width<<endl<<a.length<<endl<<a.volume<<endl<<endl;
}
box function1(box *a){
box total;
total.maker=a->maker;
total.height=a->height;
total.width=a->width;
total.length=a->length;
total.volume=(a->height*a->width*a->length);
return total;
}
int main(void){
box aa={"asfdji",2.3,5.6,4.7,7.8};
function(aa);
box bb=function1(&aa);
cout<<bb.maker<<endl<<bb.height<<endl<<bb.width<<endl<<bb.length<<endl<<bb.volume;
return 0;
}
using namespace std;
struct box{
char maker[40];
float height;
float width;
float length;
float volume;
};
void function(box a){
cout<<a.maker<<endl<<a.height<<endl<<a.width<<endl<<a.length<<endl<<a.volume<<endl<<endl;
}
box function1(box *a){
box total;
total.maker=a->maker;
total.height=a->height;
total.width=a->width;
total.length=a->length;
total.volume=(a->height*a->width*a->length);
return total;
}
int main(void){
box aa={"asfdji",2.3,5.6,4.7,7.8};
function(aa);
box bb=function1(&aa);
cout<<bb.maker<<endl<<bb.height<<endl<<bb.width<<endl<<bb.length<<endl<<bb.volume;
return 0;
}