错误-函数定义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;
        }

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...