深复制体验(3)

#include<iostream>
#include<cstring>
using namespace std;
class A
{
private:
    char *a;
public:
    A(char *aa)
    {
        a = new char[strlen(aa)+1];  //(a)这样处理的意义在于:______________________________
        strcpy(a, aa);  //(b)数据成员a与形式参数aa的关系:___________________________________
    }
    A(A &b)
    {
        a=new char[strlen(b.a)+1];
        strcpy(a,b.a);
    }
    ~A()
    {
        delete []a;   //(c)这样处理的意义在于:  ___________________________________________
    }
    void output()
    {
        cout<<a<<endl;
    }
};
int main(){
    A a("good morning, code monkeys!");
    a.output();
    A b(a);
    b.output();
    return 0;
}


 

深复制体验(3)_第1张图片

你可能感兴趣的:(深复制体验(3))