错误:请求非类类型的成员
Error:request for member of non class type
>我只是在尝试一个简单的程序来计算立方体的体积。我已经在 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
相关文章:
- 访问C++中的类型成员
- 具有 STL 向量类型成员的类的复制内存
- 重载具有 2 个相同数据类型成员的构造函数
- std::void_t 和嵌套的非类型成员
- 返回对常量结构(指针类型)成员的引用:明显的左值到右值转换
- 使用各种数据类型成员创建对象的简便方法
- 将类类型成员定义为公共和私有之间有什么区别?
- 结构类型成员的默认构造函数中的默认参数
- 如何传递模板模板非类型成员函数指针
- 文本类类型成员函数约束
- 给定仅包含布尔类型成员的结构的两个对象 s1 和 s2,只要 s1 的成员为 true,请检查 s2 的每个成员是否为真
- 如何在 c++ 中使用二进制文件输入/输出读取/写入结构的字符串类型成员
- C++:将模板参数的模板类型成员加为好友的语法正确吗
- C++静态结构类型成员初始化
- C++:作为引用或指针的基类型成员变量
- 左值引用类型成员的用户定义移动构造函数
- 具有指针类型成员的类在 MSVS2012@debug 下销毁时失败.程序错误或错误源
- CRTP -- 访问不完整的类型成员
- 为什么C++默认初始化不对非类类型成员进行零初始化
- 请求非类类型成员