实例化新对象 - 错误
Instantiating a new object - error
#include <iostream>
using namespace std;
class Vehicle{
protected:
string type;
int wheels;
bool engine; // number of engines in vehicle
public:
Vehicle(string t, int w,bool e):
type(t), wheels(w), engine(e){};
void setType(string t) {type = t;}
void setWheels(int w) {wheels = w;}
void setEngine(int e) {engine = e;} // number of engines, 0 - False.
string getType(){return type;}
int getWheels() {return wheels;}
bool getEngine() {cout << "1 - Has Engine | 0 - No Engine"; return engine;}
};
class Auto:public Vehicle {
private:
string brand;
int year;
public:
Auto(string t, int w, bool e, string b, int y):
Vehicle(t,w,e), brand(b),year(y) {};
void setBrand(string b) {brand = b;}
void setYear(int y) {year = y;}
string getBrand() {return brand;}
int getYear() {return year;}
};
int main()
{
// This first segment of the program demonstrates the relationship
// between the base class and derived class through the use of
// a constructor.
Auto Spider360("Car",4,2,"Ferrari",2000);
cout << "Car type: " << Spider360.getType() << endl;
cout << "Number of wheels: " << Spider360.getWheels() << endl;
cout << " Has Engine: " << Spider360.getEngine() << "n";
cout << "Brand: " << Spider360.getBrand() << endl;
cout << "Year: " << Spider360.getYear() << "nn";
// Now I use member functions directly to assign values to an object
Auto SuperAmerica;
return 0;
}
我无法声明对象汽车超级美国;我收到以下错误:"Auto::Auto((没有匹配的函数调用",对于SuperAmerica,我不想使用构造函数来设置值,我想使用我的Set函数。
的错误
"No matching function call for Auto::Auto()"
表示您无法以所需的方式实例化类。如果要创建对象,然后稍后使用 setter 初始化其成员,请使用默认构造函数。
相关文章:
- 在c++中尝试对对象数组进行排序时,出现std:bad_alloc错误
- 模板,函数使用错误的构造函数来复制我的对象
- 有没有办法让编译器在我放置字符串而不是 nlohmann::json 对象时抛出错误?
- std::unordered_map 类型对象声明期间出现"field has incomplete type"错误
- 错误:malloc:对象 0x7f9edf504080 的 *** 错误:未分配正在释放的指针
- 从对象C++中的文件读取内容时出现分段错误
- cout 新创建的对象引发运行时错误
- 错误:"释放后使用包装器对象 (WRAPPER_ESCAPE)"
- 使用返回对象的函数处理错误
- 创建 QtChart 对象会在运行时创建EXC_BAD_ACCESS错误
- 错误:无法传递非平凡类型"std::string"的对象和更多错误
- 该对象具有与成员函数不兼容的类型限定符.为什么会出现此错误?
- 如何在类模板的成员函数中正确调用函数对象?正在生成 Visual Studio 编译器错误 C2440
- 尝试将对象插入空指针数组时出现分段错误
- 错误:三元运算符无法在对象中正常工作"cout"
- C++:如果括号为空,为什么不抛出错误对象?
- qt vsaddin错误对象引用未设置为对象的istanse
- 如何从函数返回成功或错误对象?
- 复制构造函数错误:对象的类型限定符与成员函数不兼容
- 如何在本机插件中创建node.js错误对象