hello world

hello _word

/*              E2_T3             */

class Person 
{
    private:
        string name;
        int age;
    public:
        Person(string _name,int _age):name(_name),age(_age){}
        string get_name(void) const { return name; }
        int get_age(void) const {  return age; };
};
class Leader :virtual /*虚基类*/ public Person     
{
    private:
        string department;
        string position;
    public:
        Leader(string _name,int _age,string _depart,string _posi) :\
        Person(_name,_age),department(_depart),position(_posi) {}
        void showInfo(void) const
        {
            cout<<">>Leader Information<<"<<endl;
            cout<<"name: "<<get_name()<<endl;                   //由于 name为基类的 private 成员 在派生类不可见  解决方法:基类给出获取name数据的接口
            cout<<"age: "<<get_age()<<endl;
            cout<<"position: "<<position<<endl;
            cout<<"department: "<<department<<endl;
            cout<<endl;     
        }
        string get_position(void) const{ return position;};
        string get_department(void) const { return department;};
};
class Engineer :virtual/*虚基类*/ public Person
{
    private:
        string position;    //职务
        string speciality;  //专业  
    public :
        Engineer(string _name,int _age,string _posi,string _spec):\
                Person(_name,_age),position(_posi),speciality(_spec) {}
        void showInfo(void ) const 
        {
            cout<<">>Engineer Information<<"<<endl;
            cout<<"name: "<<get_name()<<endl;                   //由于 name为基类的 private 成员 在派生类不可见  解决方法:基类给出获取name数据的接口
            cout<<"age: "<<get_age()<<endl;
            cout<<"position: "<<position<<endl;
            cout<<"speciality: "<<speciality<<endl;
            cout<<endl;              
        }
        string get_position(void) const{ return position;};
        string get_speciality(void) const { return speciality;};
};
//虚继承 确保 在派生类当中 仅有一个 第一级 基类的 成员 

class Chairman: public Leader, public Engineer    
{
    private:
    //
    public:
    Chairman(string _name,int _age,string _depa,string _posi,string _spec):\
            Person(_name,_age),Leader(_name,_age,_depa,_posi),\
            Engineer(_name,_age,_posi,_spec)\
            {}  //Construction
    void showInfo(void) const
    {
            cout<<">>Chairman Information<<"<<endl;
            cout<<"name: "<<get_name()<<endl;                   //由于 name为基类的 private 成员 在派生类不可见  解决方法:基类给出获取name数据的接口
            cout<<"age: "<<get_age()<<endl;
            cout<<"department: "<<get_department()<<endl;
            cout<<"position: "<<Engineer::get_position()<<endl;
            cout<<"speciality: "<<get_speciality()<<endl;
            cout<<endl;           
    }

};

//虚基类 不能实例化?   系统限定还是语意上  不建议??

int main()
{
    
    Leader  Ldr_1("ZhangWei",25,"D&R","chief inspector");
    Ldr_1.showInfo();
    
    Engineer Egr_1("Huhao",23,"developer","computer science");
    Egr_1.showInfo();

    Chairman ChM_1("Jony J",28,"Sales","Chairman","E-information");
    ChM_1.showInfo();

    return 0;
}

/*              END               */
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值