如何解决错误-函数定义C ++中的“ ...之前预期的主表达式”
尝试在在线编译器中运行此错误,但出现错误-“预期的主表达式在'之前。”。在所有4个结构成员的函数定义中:'高度,宽度,长度,体积。在Visual Studio中,错误是“框”非法使用此类型作为表达式。可能是什么原因?
#include <iostream>
using namespace std;
struct box
{
float height;
float width;
float length;
float volume;
};
void display(box amazon);
int main()
{
box amazon
{
10,10,10
};
display(amazon);
return 0;
}
void display(box amazon)
{
cout<<"Box height: "<<box.height;
cout<<"Box width: "<<box.width<<"Box length: "<<box.length<<"Box volume: "<<box.volume;
}
解决方法
在display
函数中,您必须更改box
(即类型)和amazon
(即对象)
void display(box amazon)
{
cout<<"Box height: "<<amazon.height;
cout<<"Box width: "<<amazon.width<<"Box length: "<<amazon.length<<"Box volume: "<<amazon.volume;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。