您的位置:首页 > 其它

复制深体验2

2016-05-10 16:23 351 查看
#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( const A &obj)
{

a= new char[strlen(obj.a)+1];
strcpy(a,obj.a);
}
~A()
{
delete []a;
}
void output(){cout<<a<<endl;}
};

int main()
{
A a("good moring, code monkeys!");
a.output();
A b(a);
b.output();
return 0;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: