class vehicle
{
int MaxSpeed;
int Weight;
public:
vehicle(int maxspeed, int weight) :MaxSpeed(maxspeed), Weight(weight){}
~vehicle(){}
int getMaxspeed()const { return MaxSpeed; }
int getWeight()const { return Weight; }
};
class bicycle: virtual public vehicle
{
int Height;
public:
bicycle(int maxspeed, int weight, int height)
:vehicle(maxspeed, weight), Height(height){}
int getHeight()const { return Height; }
};
class motorcar :virtual public vehicle
{
int SeatNum;
public:
motorcar(int maxspeed, int weight, int seatnum) :vehicle(maxspeed, weight), SeatNum(seatnum){}
int getseatnum()const{ return SeatNum; }
};
class motorcycle : public bicycle,public motorcar
{
public:
motorcycle(int maxspeed, int weight, int height) :
vehicle(maxspeed, weight), bicycle(maxspeed, weight, height),
motorcar(maxspeed, weight, 1){}

};

int _tmain()
{
motorcycle a(80, 150, 100);
cout << a.getMaxspeed() << endl;
cout << a.getWeight() << endl;
cout << a.getHeight() << endl;
cout << a.getseatnum() << endl;

}

相关文章:

  • 2022-01-09
  • 2021-11-12
  • 2022-12-23
  • 2022-01-09
  • 2021-06-18
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-30
  • 2021-11-11
  • 2022-12-23
相关资源
相似解决方案