C++ motorcycle类(虚继承)

版权声明:版权所有 如有侵权 概不追究 https://blog.csdn.net/weixin_40903417/article/details/87870419
#include "stdafx.h"
using namespace std;
class vehicle
{
public:
	int MaxSpeed;
	int Weight;
	vehicle(int v=220,int w=20):MaxSpeed(v),Weight(w){}
	void Run()
	{
		cout<<"Vehicle runs..."<<endl;
	}
	void Stop()
	{
		cout<<"Vehicle stops!"<<endl;
	}
};
class bicycle:virtual public vehicle
{
public:
	int Height;
	bicycle(int v=220,int w=20,int h=1):vehicle(v,w),Height(h){}
	
};
class motorcar:virtual public vehicle
{
public:
	int SeatNum;
	motorcar(int v=220,int w=20,int n=5):vehicle(v,w),SeatNum(n){}
};
class motorcycle:public bicycle,public motorcar
{
public:
	motorcycle(int v=220,int w=20,int h=1,int n=5):vehicle(v,w),bicycle(v,w,h),motorcar(v,w,n){}
};
int main()
{
	motorcycle a;
	a.Run();
	a.Stop();
	system("Pause");
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_40903417/article/details/87870419
今日推荐