/*
*Copyright (c) 2016,烟台大学计算机学院
*All rights reserved.
*文件名称 :
*作 者 : 田志伟
*完成日期 : 2016年5月10号
*版 本 号 : v1.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()
{
delete []a;
}
void output() { cout<<a<<endl; }
A(A&p)
{
a=new char[strlen(p.a)+1];
strcpy(a,p.a);
}
};
int main(){
A a("good morning, code monkeys!");
a.output();
A b(a);
b.output();
return 0;
}
程序运行: