#include <iostream>
#include <cstring>
using namespace std;
//学生类
class Student
{
protected:
string name;
int age;
double score;
public:
//无参构造
Student(){cout<<"Student::无参构造"<<endl;}
//有参构造
Student(string n,int a,double s):name(n),age(a),score(s)
{
cout<<"Student::有参构造"<<endl;
}
//拷贝构造函数
Student(const Student &other):name(other.name),age(other.age),score(other.score)
{
cout<<"Student::拷贝构造函数"<<endl;
}
//拷贝赋值函数
Student &operator=(const Student &other)
{
if(this != &other)
{
this->name = other.name;
this->age = other.age;
this->score = other.score;
}
cout<<"Student::拷贝赋值函数"<<endl;
return *this;
}
//析构函数
~Student()
{
cout<<"Student::析构函数"<<endl;
}
//show函数
void show()
{
cout<<"name = "<<name<<endl;
cout<<"age = "<<age<<endl;
cout<<"score = "<<score<<endl;
}
};
//党员类
class Party
{
private:
string activity;
string orgz;
public:
//无参构造
Party(){cout<<"Party::无参构造"<<endl;}
//有参构造
Party(string a,string o):activity(a),orgz(o)
{
cout<<"Party::有参构造"<<endl;
}
//拷贝构造函数
Party(const Party &other):activity(other.activity),orgz(other.orgz)
{
cout<<"Party::拷贝构造函数"<<endl;
}
//拷贝赋值函数
Party &operator=(const Party &other)
{
if(this != &other)
{
this->activity= other.activity;
this->orgz = other.orgz;
}
cout<<"Party::拷贝赋值函数"<<endl;
return *this;
}
//析构函数
~Party()
{
cout<<"Party::析构函数"<<endl;
}
//show函数
void show()
{
cout<<"activity = "<<activity<<endl;
cout<<"orgz= "<<orgz<<endl;
}
};
//派生的学生干部类
class Stu_leader:public Student,public Party
{
private:
string position;
public:
//无参构造
Stu_leader(){cout<<"Stu_leader::无参构造"<<endl;}
//有参构造
Stu_leader(string n,int a ,double s,string a1,string o,string p):Student(n,a,s),Party(a1, o),position(p)
{
cout<<"Stu_leader::有参构造"<<endl;
}
//拷贝构造函数
Stu_leader(const Stu_leader &other):Student(other),Party(other)
{
cout<<"Stu_leader::拷贝构造函数"<<endl;
}
//拷贝赋值函数
Stu_leader &operator=(const Stu_leader &other)
{
if(this != &other)
{
this->position = other.position;
//调用学生类拷贝赋值函数
Student::operator=(other);
//调用党员类拷贝赋值函数
Party::operator=(other);
}
cout<<"Stu_leader::拷贝赋值函数"<<endl;
return *this;
}
//析构函数
~Stu_leader()
{
cout<<"Stu_leader::析构函数"<<endl;
}
//show函数
void show()
{
cout<<"Student::name = "<<name<<endl;
cout<<"Student::age = "<<age<<endl;
cout<<"Student::score = "<<score<<endl;
cout<<"Stu_leader::position = "<<position<<endl;
}
};
int main()
{
Student s1("sss",20,99);
Student s2 = s1;
Student s3;
s3 = s1;
s1.show();
s2.show();
s3.show();
cout<<"*******************************************"<<endl;
Party l1("运动会","体育部");
Party l2 = l1;
Party l3;
l3 = l1;
l1.show();
l2.show();
l3.show();
cout<<"*******************************************"<<endl;
Stu_leader p1("xkw",19,88,"运动会","体育部","干事");
p1.show();
Stu_leader p2 = p1;
p2.show();
Stu_leader p3;
p3 = p1;
p3.show();
return 0;}