无法在C ++中编译继承赋值

时间:2017-01-26 03:33:20

标签: inheritance

所以Ship是我的基类,当我注释掉构建我的子类对象的行时,我可以使Ship对象变好。我不确定如果我正在调用构造函数错误或者子类没有正确生成。我只是包含了子类和main方法,试图保持代码简洁

    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;
}

0 个答案:

没有答案