1.xmind
2.
- #include
-
- using namespace std;
-
- class Per
- {
- private:
- string name ;
- int age;
- double * high;
- double * wegiht;
- public:
- Per(string n,int a,double h,double w):name(n),age(a),high(new double(h)),wegiht(new double(w))
- {
- cout << "Per :有参构造函数" << endl;
- }
-
- ~Per()
- {
- cout << "Per : 析构函数" << endl;
- delete(high);
- delete(wegiht);
- }
-
- Per(const Per &other):name(other.name),age(other.age),high(other.high),wegiht(other.wegiht)
- {
- cout << "Per : 拷贝构造函数" << endl;
- }
- };
-
- class Stu
- {
- private:
- double score;
- Per p1;
- public:
- Stu(double s,string n,int a,double h,double w):score(s),p1(n,a,h,w)
- {
- cout << "Stu : 有参构造函数" << endl;
- }
- ~Stu()
- {
- cout << "Stu : 析构函数" << endl;
- }
- Stu(const Stu &other):score(other.score),p1(other.p1)
- {
- cout << "Stu : 拷贝构造函数" << endl;
- }
-
- };
-
- int main()
- {
- Stu s1(100,"zhangsan",12,40,145);
- Stu s2(s1);
-
- return 0;
- }