#include using namespace std;

class Vehicle { public: Vehicle() { cout << 'Vehicle类对象构造成功!' << endl; } void SetWeight(int weight) { this->weight = weight; cout << '重置重量:' << weight << endl; } void ShowMe() { cout << 'I'm vehicle!' << endl; } protected: int weight; };

class Car : public Vehicle { public: Car() { cout << 'Car类对象构造成功!' << endl; aird = 0; } void ShowMe() { cout << 'I'm car!' << endl; } protected: int aird; };

class Boat : public Vehicle { public: Boat() { cout << 'Boat类对象构造成功!' << endl; tonnage = 0; } void ShowMe() { cout << 'I'm boat!' << endl; } protected: float tonnage; };

class AmphibianCar : public Car, public Boat { public: AmphibianCar(int weight, int aird, float tonnage) { cout << '载入AmphibianCar类对象构造成功!' << endl; this->weight = weight; this->aird = aird; this->tonnage = tonnage; } void ShowMe() { cout << 'I'm amphibianCar!' << endl; } void ShowMembers() { cout << '重量:' << weight << '顿,' << '空气排量:' << aird << 'CC,' << '排水量:' << tonnage << '顿' << endl; } };

int main() { AmphibianCar a(4, 200, 1.35f); a.ShowMe(); a.ShowMembers(); a.SetWeight(3); a.ShowMembers(); return 0; }


原文地址: https://www.cveoy.top/t/topic/nHMe 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录