您的位置:首页 > 其它

第六周项目一深复制体验(3)

2015-04-15 08:47 246 查看
*Copyright (c)2015,烟台大学计算机与控制工程学院
*All rights reserved.
*文件名称:test.cpp
*作 者:李文贺
*完成日期:2015年4月15日
*版 本 号: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(const A&b);
};
A::A(const A &b)
{
a=new char[strlen(b.a)+1];
strcpy(a,b.a);
}

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


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