第九周 深复制体验

问题及代码:

/*
 *copyright(c) 2016烟台大学计算机学院
 *All rights reserved
 *文件名称:test.cpp
 *作者:杨昊
 *版本:v6.0
 *
 *问题描述: 第九周深复制体验
 *输入描述:无
 *程序输出:
*/

#include<iostream>
#include<cstring>
using namespace std;
class A
{
private:
    char *a;
public:
    A(char *aa)
    {
        a = new char[strlen(aa)+1];
        strcpy(a,aa);
    }
    A(A &b)
    {
        a = new char[strlen(b.a)+1];
        strcpy(a,b.a);
    }
    ~A()
    {
        delete []a;
    }
    void output()
    {
        cout<<a<<endl;
    }
};
int main(){
    A a("good morning, code monkeys!");
    a.output();
    A b(a);
    b.output();
    return 0;
}


结果及总结:

第九周 深复制体验_第1张图片

你可能感兴趣的:(第九周 深复制体验)