#include <iostream>
using namespace std;
class Person
{
int *age;
string &name;
public:
Person(int age,string &name):age(new int(age)),name(name)
{
cout<<"Person两个参数的有参构造函数"<<endl;
}
Person(const Person &other):age(new int(*(other.age))),name(other.name)
{
cout<<"Person拷贝构造函数"<<endl;
}
Person&operator=(const Person &other)
{
*(this->age)=*(other.age);
this->name=other.name;
cout<<"Person拷贝赋值函数"<<endl;
return *this;
}
~Person()
{
cout<<"Person析构函数"<<endl;
delete age;
}
int get_age();
string get_name();
};
class Stu
{
double *score;
Person p1;
public:
Stu(double score):score(new double(score)),p1(p1)
{
cout<<"Stu一个参数有参构造函数"<<endl;
}
Stu(const Stu &other):score(new double(*(other.score))),p1(other.p1)
{
cout<<"Stu拷贝构造函数"<<endl;
}
Stu &operator=(const Stu &other)
{
*(this->score)=*(other.score);
this->p1=other.p1;
cout<<"Stu拷贝赋值函数"<<endl;
return *this;
}
~Stu()
{
cout<<"Stu析构函数"<<endl;
delete score;
}
void show(Person p1);
};
int Person::get_age()
{
return *age;
}
string Person::get_name()
{
return name;
}
void Stu::show(Person p1)
{
cout<<"年龄"<<p1.get_age()<<endl;
cout<<"姓名"<<p1.get_name()<<endl;
cout<<"成绩"<<*score<<endl;
}
int main()
{
Person p1(18,"张三");
Stu s1(88);
s1.show(p1);
return 0;
}