2
#include <iostream>
using namespace std;
class Person{
int *age;
string &name;
public:
Person(int age,string name):age(new int(age)),name(name){}
~Person(){
delete age;
}
Person(const Person &other):age(new int (*(other.age))),name(other.name){}
Person &operator=(const Person &other){
this->name=other.name;
*(this->age)=*(other.age);
return *this;
}
int get_age();
string get_name();
};
int Person::get_age(){
return *age;
}
string Person::get_name(){
return name;
}
class Stu{
double *score;
Person p1;
public:
Stu(double score,int age,string name):score(new double(score)),p1(age,name){}
~Stu(){
delete score;
}
Stu(const Stu &other):score(new double(*(other.score))),p1(other.p1){}
Stu &operator=(const Stu &other){
*(this->score)=*(other.score);
this->p1=other.p1;
return *this;
}
void show(){
cout<<"score="<<*score<<endl;
cout<<"age="<<p1.get_age()<<endl;
cout<<"name="<<p1.get_name()<<endl;
}
};
int main()
{
Stu s2(100,20,"zhangsan");
s2.show();
return 0;
}