错误:请求非类型成员

时间:2016-02-28 12:18:01

标签: c++ class object

我只是在尝试一个计算立方体体积的简单程序。我在main中声明了该对象,当我尝试使用用户输入参数访问该类的函数时,它显示一个错误:请求成员' volume cube'在' 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;

}

1 个答案:

答案 0 :(得分:1)

你刚刚成为C ++ Most Vexing Parse

的受害者

改变这个:

Vellimi vol();

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