C++Day3

#include 

using namespace std;

class Per
{
private:
    string name;
    int age;
    double* height;
    double* weight;

public:
    Per()
    {
        cout << "Per::默认构造函数" << endl;
    }

    Per(string name, int age , double height, double weight):name(name),age(age),height(new double(height)),weight(new double(weight))
    {
        cout << "Per::有参构造函数" << endl;
    }

    Per(const Per &other):name(other.name),age(other.age),height(other.height),weight(other.weight)
    {
        cout << "Per::拷贝构造函数" << endl;
    }

    ~Per()
    {
        cout << "Per::析构函数" << endl;
    }

};

class Stu
{
private:
    int score;
    Per p1;

public:
    Stu()
    {
        cout << "Stu::默认构造函数" << endl;
    }

    Stu(int score,string name,int age,double height,double weight):score(score),p1(name,age,height,weight)
    {
        cout << "Stu::有参构造函数" << endl;
    }

    Stu(const Stu &other):score(other.score),p1(other.p1)
    {
        cout <<"Stu::拷贝构造函数" << endl;
    }

    ~Stu()
    {
        cout << "Stu::析构函数" << endl;
    }

};

int main()
{
    Stu s1;
    Stu s2(97,"zhouxingxing",18,180,150);
    Stu s3(s2);
    Stu s4=s2;

    return 0;
}

 

你可能感兴趣的:(linux,c++)