#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()
{
cout<<"P析构"<<endl;
delete age;
}
int getp();
string getps();
int *gage()
{
return age;
}
};
int Person::getp()
{
return *age;
}
string Person::getps()
{
return name;
}
class Stu
{
double *score;
Person p1;
public:
void show();
Stu (double a,int age,string name):score(new double(a)),p1(age,name)
{
cout<<"Stu有参构造"<<endl;
}
~Stu()
{
cout<<"S析构"<<endl;
delete score;
}
Stu (const Stu&other):score(new double(*(other.score))),p1(other.p1)
{
cout<<"S拷贝"<<endl;
}
};
void Stu::show()
{
cout<<"score"<<score<<endl;
cout<<"*SCORE="<<*score<<endl;
cout<<"age"<<p1.gage()<<endl;
cout<<"*age"<<p1.getp()<<endl;
cout<<"name="<<p1.getps()<<endl;
}
int main()
{
Stu s1(90.1,10,"zhangss");
s1.show();
cout<<"----------------------"<<endl;
Stu s2(s1);
s2.show();
return 0;
}
2.思维导图