#include <iostream>
using namespace std;
class Per
{
private:
string name;
int age;
int *heigh;
int *weight;
public:
//无参构造函数
Per()
{
cout << "没有参数" << endl;
}
//有参构造函数
Per(string n,int a, int h,int w) : name(n),age(a),heigh(new int(h)),weight(new int(w))
{
cout << "有参Per" << endl;
}
void show()
{
cout << name << endl << age << endl << *heigh << endl << *weight << endl;
}
//拷贝构造函数,指针成员
Per(const Per &other):name(other.name),age(other.age),heigh(new int(*(other.heigh))),weight(new int(*(other.weight)))
{
cout << "拷贝Per" << endl;
}
//析构函数
~Per()
{
delete heigh;
delete weight;
cout << "Per析构函数" << endl;
}
};
class Stu
{
private:
int score;
Per per;
public:
//无参数构造类型
Stu()
{
cout << "无参数构造" << endl;
}
Stu(int s,string n,int a,int h,int w):score(s),per(n,a,h,w)
{
cout << "Stu 构造" << endl;
}
Stu(const Stu &other):score(other.score),per(other.per)
{
cout << "构造Stu" << endl;
}
};
int main()
{
//有参构造
Per pp("ljb",12,123,321);
//拷贝构造
Per PP=pp;
PP.show();
Stu WW(99,"AAA",12,21,222);
Stu QQ=WW;
return 0;
}