您的位置:首页 > 其它

第九周项目1-深度复制体验(3)

2016-04-28 08:13 363 查看
问题及代码:

/*

*Copyright (c) 2016,烟台大学计算机学院

*All rights reserved.

*文件名称:zwj.cpp

*作 者:张晴晴

*完成日期:2016年4月28日

*版 本 号:v1.0 *

*问题描述:深复制

*输入描述:

*程序输出:

*/

#include<iostream>
#include<cstring>
using namespace std;
#include<iostream>
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()
{
delete []a;   //(c)这样处理的意义在于:

}
void output() { cout<<a<<endl; }
};
/*
int main(){
A a("good morning, code monkeys!");
a.output();
A b("good afternoon, codes!");
b.output();
return 0;
}
*/
int main()
{
A a("good morning, code monkeys!");
a.output();
A b(a);
b.output();
return 0;
}


运行结果:

现在的:



原来的:



学习心得:

学习怎么为A增加复制构造函数。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: