5.19 设计一个虚基类



#include <iostream>
#include <string>
using namespace std;
class base{
private:
	string name;
	int old;
public:
	base(string name1,int old1)
	{
		name=name1;
		old=old1;
	}
	void print()
	{
		cout<<"姓名为:"<<name<<endl;
		cout<<"年龄为:"<<old<<endl;
	}
};
class leader:virtual public base{
public:
	string position;
	string department;
public:
	leader(string name1,int old1,string position1,string department1):base(name1,old1)
	{
		position=position1;
		department=department1;
	/*}
	void print()
	{*/
		base::print();
		cout<<"职务为:"<<position<<endl;
		cout<<"部门为:"<<department<<endl;
	}
};
class engineer:virtual public base{
private:
	string job_name;
	string major;
public:
	engineer(string name1,int old1,string job_name1,string major1):base(name1,old1)
	{
		job_name=job_name1;
		major=major1;
	/*}
	void print()
	{
		base::print();*/
		cout<<"职称为:"<<job_name<<endl;
		cout<<"专业为:"<<major<<endl;
	}
};
class chairman:public leader,public engineer{
public:
	chairman(string name1,int old1,string position1,string department1,string job_name1,string major1):base(name1,old1),leader(name1,old1,position1,department1),engineer(name1,old1,job_name1,major1)
	{ 
		
		//print();
	}
	/*void print()
	{
		base::print();
		leader::print();
		engineer::print();
	}*/
};
int main()
{
	cout<<"chairman的信息为:"<<endl;
	chairman C("zhang",25,"director","engineer department","director chairman","engineer science");
	return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值