我无法让我的代码打印获取音量功能


#include <iostream>
using namespace std;
class Box
{
public:
double length;
double breadth;
double height;
void getvolume();
void setlength( double len)
{
length=len;
}
void setbreadth( double bre)
{
breadth=bre;
}
void setheight(double hei)
{
height=hei;
}
};
void Box::getvolume()
{
double volume=0.0;
volume= length*breadth*height;
cout<<volume;
}
int main()
{
double volume1=0.0,volume2=0.0;
Box box1;
Box box2;
//box 1 dimensions
box1.setlength(12.0);
box1.setbreadth(14.7);
box1.setheight(19.5);
//box 2 dimensions
box2.setlength(3.4);
box2.setbreadth(2.2);
box2.setheight(23.4);
cout<<"the volume of box 1 is";
box1.getvolume;
return 0;
}

在最近的代码,我已经上传我收到错误:语句无法解析重载函数的地址我尝试过使用双返回类型和void返回类型在类内部移动获取体积,并调用具有和不具有范围解析操作符的函数,还尝试将该函数调用为另一个变量volume1的值。

int main()
{
double volume1=0.0,volume2=0.0;
Box box1;
Box box2;
//box 1 dimensions
box1.setlength(12.0);
box1.setbreadth(14.7);
box1.setheight(19.5);
//box 2 dimensions
box2.setlength(3.4);
box2.setbreadth(2.2);
box2.setheight(23.4);
cout<<"the volume of box 1 is";
box1.getvolume();
return 0;
}

你只需要把box1.getvolume改成box1.getvolume()

您需要使用call()操作符调用getvolume函数

box1.getvolume();

最新更新