12.28

#include 
using namespace std;

class Person
{
    int *age;
    string &name;
public:
    //构造函数
    Person(string &name):age(new int),name(name)
    {}
    Person(int age,string &name):age(new int(age)),name(name)
    {}
    //拷贝构造函数(深拷贝)
    Person(const Person &other):age(new int(*(other.age))),name(other.name)
    {}
    //拷贝赋值函数
    Person &operator=(const Person &other)
    {
        *(this->age)=*(other.age);
        this->name = other.name;
    }
    void show_p();
    //析构函数
    ~Person()
    {
        delete age;
    }
};
class Stu
{
    double *score;
    Person p1;
public:
    //构造函数
    Stu(string name="susu"):score(new double),p1(name)
    {}
    Stu(double score,int age,string &name):score(new double(score)),p1(age,name)
    {}
    //拷贝构造函数
    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;
    }
    void show();
    //析构函数
    ~Stu()
    {
        delete score;
    }

};
void Person::show_p()
{
    cout << "age=" <<*age <

12.28_第1张图片

你可能感兴趣的:(前端,javascript,开发语言)