C++继承

#include <iostream>

using namespace std;
class student
{
private:
    string name;
    int age;
    float score;
public:
    student() {cout<<"student 无参构造"<<endl;}
    //构造
    student(string name, int age, float score):name(name),age(age),score(score) {cout<<"student 有参构造"<<endl;}
    //析构
    ~student(){};
    void show()
    {
        cout<<"name = "<<name<<" age= "<<age<<" score = "<<score<<endl;
    }
};


class party
{
private:
    string dang_act;
    string team;
public:
    party() {cout<<"party 无参构造"<<endl;}
    //构造
    party(string dang_act, string team):dang_act(dang_act),team(team) {cout<<"party 有参构造"<<endl;}
    //析构
    ~party(){};
    void show()
    {
        cout<<"dang_act = "<<dang_act<<" team= "<<team<<endl;
    }
};
//:public student,public party
class leader:public student, public party
{
private:
    string job;
public:
    //构造
    leader() {}
   leader(string name, int age, float score,string dang_act, string team,string job) :student(name, age, score),party(dang_act, team),job(job) {}


    void show()
    {
//        this->student::show();
//       this->party::show();
        student::show();
      party::show();
       cout<<"job = "<<job<<endl;
    }

};
int main()
{
   leader l1("zpp", 50, 99.3, "hqyj", "2023021", "teacher");
 
   l1.show();
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值