12.28

12.28_第1张图片

2

#include 

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<

12.28_第2张图片

你可能感兴趣的:(作业,程序人生)