错误:请求非类类型的成员

Error:request for member of non class type

本文关键字:类型 成员 请求 错误      更新时间:2023-10-16

>我只是在尝试一个简单的程序来计算立方体的体积。我已经在 main 中声明了该对象,当我尝试使用用户输入参数访问类的功能时,它显示一个错误:请求"vol"中的成员"体积立方体",其非类类型为"Vellimi()"。为什么会这样?

#include <iostream>
using namespace std;
class Vellimi {
private:
double width;
double height;
double length;
public:
Vellimi(double,double,double);
double volume_cube (double width,double height,double length)
{
    return width*height*length;
}
};
  Vellimi::Vellimi(double a,double b,double c){
  width=a;
   height=b;
   length=c;
}
int main()
{
   double x,y,z;
   Vellimi vol();
   cout<<"Input the width : "<<endl;
   cin>>x;
   cout<<"Input the height : "<<endl;
   cin>>y;
   cout<<"Input the length : "<<endl;
   cin>>z;
   cout<<"The volume is "<<vol.volume_cube(x,y,z)<<endl;
   return 0;
}

你刚刚成为C++最令人烦恼的解析的受害者

更改此设置:

Vellimi vol();

Vellimi vol(0, 0, 0); //or
//Vellimi vol; Unfortunately, you have no default constructor