C++ 类设计:汽车、客车、货车、客货两用车
class CAR { protected: int speed; public: CAR(int s) { speed = s; } ~CAR() { } void Show() { cout'Speed: ' << speed << endl; } };
class BUS : public CAR { protected: int seat; public: BUS(int s, int t) : CAR(s) { seat = t; } ~BUS() { } void Show() { cout'Speed: ' << speed << endl; cout'Seat: ' << seat << endl; } };
class TRUCK : public CAR { protected: int load; public: TRUCK(int s, int t) : CAR(s) { load = t; } ~TRUCK() { } void Show() { cout'Speed: ' << speed << endl; cout'Load: ' << load << endl; } };
class VAN : public BUS, public TRUCK { public: VAN(int s, int t, int u) : BUS(s, t), TRUCK(s, u), CAR(s) { } ~VAN() { } void Show() { cout'Speed: ' << speed << endl; cout'Seat: ' << seat << endl; cout'Load: ' << load << endl; } };
原文地址: https://www.cveoy.top/t/topic/nOue 著作权归作者所有。请勿转载和采集!