第九周项目1-深度复制体验(3)
2016-04-28 08:13
363 查看
问题及代码:
运行结果:
现在的:
原来的:
学习心得:
学习怎么为A增加复制构造函数。
/* *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增加复制构造函数。
相关文章推荐
- 总结一些前端面试题
- Android-AlertDialog各种对话框的用法
- [C语言][LeetCode][448]Find All Numbers Disappeared in an Array
- POJ 2586-Y2K Accounting Bug(贪心)
- IPTV的开展在广电企业、电信运营商角度上的异同
- 静态库和动态库的创建和使用
- 使用Git上传本地代码到http://git.oschina.net/(SSH方式)
- Python之No module named setuptools 安装pip
- GDOI2016第二次模拟总结 4.25 ~ 4.27
- Linux基础(软件安装)
- tomcat 8.0特性
- hao dongxi
- 【codevs3052&&1022】多米诺&覆盖,二分图
- pku 2769 - Reduced ID Numbers
- tomcat7.0 特性
- Win7下SQL2012安装教程图文版
- Win7+Ubuntu双系统安装完成后时间不一致相差大概8小时
- Win7+Ubuntu双系统安装完成后时间不一致相差大概8小时
- 【Unity3d开发记录】Unity动态画曲线、弧线(GL画线)在UI上的显示
- Ecplise打开xml文件时报Failed to create the part's controls错误