Inheritance 在C+中编译继承赋值时出现问题+;
所以Ship是我的基类,当我注释出构建子类对象的行时,我可以使Ship对象变得很好。我不确定我是否调用了错误的构造函数,或者子类是否没有正确生成。我只是包含了子类和main方法,试图保留代码breifInheritance 在C+中编译继承赋值时出现问题+;,inheritance,Inheritance,所以Ship是我的基类,当我注释出构建子类对象的行时,我可以使Ship对象变得很好。我不确定我是否调用了错误的构造函数,或者子类是否没有正确生成。我只是包含了子类和main方法,试图保留代码breif class cargoShip : public Ship { public: cargoShip(); cargoShip(string, int); void setCapa
class cargoShip : public Ship
{
public:
cargoShip();
cargoShip(string, int);
void setCapacity(int);
int getCapacity();
void printInfo();
private:
int capacity;
};
int main()
{
Ship shipObj;
cruiseShip cruiseObj;
cargoShip cargoObj;
string tempName;
int tempYear;
cout << "" << endl;
cout << "Please enter the name of the Ship: " << endl;
cin >> tempName;
shipObj.setName(tempName);
cout << "Please enter the year the Ship was built: " << endl;
cin >> tempYear;
shipObj.setYear(tempYear);
cout << "Now printing the Objects created using constructor with arguments:" << endl;
shipObj.printInfo();
cout << "" << endl;
cout << "" << endl;
cout << "Please enter the name of the Cruise Ship: " << endl;
cin >> tempName;
cruiseObj.setName(tempName);
cout << "Please enter the year the Cruise Ship was built: " << endl;
cin >> tempYear;
cruiseObj.setMaxPassengers(tempYear);
cout << "Now printing the Objects created using constructor with arguments:" << endl;
cruiseObj.printInfo();
cout << "" << endl;
cout << "" << endl;
return 0;
}
级货船:公共船舶
{
公众:
货船();
货船(字符串,整数);
空隙率(int);
int getCapacity();
void printInfo();
私人:
国际能力;
};
int main()
{
船舶shipObj;
cruiseShip cruiseObj;
货船卡哥特OBJ;
字符串tempName;
年内;
cout什么错误你明白了吗?你创建子对象的方式看起来还不错。如果没有代码,就无法判断子类是否正确……我忘了提到,当我遇到错误时,行号中不会像往常一样出现一个小红色标记。因此,这只会让我更加困惑,因为我无法阅读错误的描述。我不确定如果我把我的全部代码都放进去,我会不会被炒鱿鱼。我想尽量避免关闭帖子