- 1、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
C程序设计清华大学课件-c第6章
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 要点: 如何理解第一个例子?可以看成由一维数组构成的数组。第一维表示相应行的首地址。 介绍二维数组的存储顺序是按行存储。 当需要引用数组时,需要包含数组名、行下标和列下标。 * * * * * * * * * * * * * * * * * * * * * * * * * * * 动态内存释放函数 void free( void *memblock ); 参数memblock: 指针,指向需释放的 内存。 返回值:无 头文件:cstdlib 和 cmalloc 动态存储分配 * 浅拷贝与深拷贝 浅拷贝 实现对象间数据元素的一一对应复制。 深拷贝 当被复制的对象数据成员是指针类型时,不是复制该指针成员本身,而是将指针所指的对象进行复制。 浅拷贝与深拷贝 * 例6-20对象的浅拷贝 #includeiostream using namespace std; class Point { //类的声明同例6-16 //…… }; class ArrayOfPoints { //类的声明同例6-18 //…… }; 浅拷贝与深拷贝 void main() { int number; cinnumber; ArrayOfPoints pointsArray1(number); pointsArray1.Element(0).Move(5,10); pointsArray1.Element(1).Move(15,20); ArrayOfPoints pointsArray2(pointsArray1); coutCopy of pointsArray1:endl; coutPoint_0 of array2: pointsArray2.Element(0).GetX() , pointsArray2.Element(0).GetY()endl; coutPoint_1 of array2: pointsArray2.Element(1).GetX() , pointsArray2.Element(1).GetY()endl; * pointsArray1.Element(0).Move(25,30); pointsArray1.Element(1).Move(35,40); coutAfter the moving of pointsArray1:endl; coutPoint_0 of array2: pointsArray2.Element(0).GetX() , pointsArray2.Element(0).GetY()endl; coutPoint_1 of array2: pointsArray2.Element(1).GetX() , pointsArray2.Element(1).GetY()endl; } * 运行结果如下: Please enter the number of points:2 Default Constructor called. Default Constructor called. Copy of pointsArray1: Point_0 of array2: 5, 10 Point_1 of array2: 15, 20 After the moving of pointsArray1: Point_0 of array2: 25, 30 Point_1 of array2: 35, 40 Deleting... Destructor called. Destructor called. Deleting... 接下来程序出现异常,也就是运行错误。 * 拷贝前 拷贝后 pointsArray1的数组元素占用的内存 points numberOfPoints pointsArray1 points numberOfPoints pointsArray1 pointsArray1的数组元素占用的内存 points numberOfPoints pointsArray2 * * 例6-21对象的深拷贝 #includ
您可能关注的文档
- 高三英语课件M10 Unit.3 workbook.ppt
- 高中短文改错解题技巧.ppt
- 高三英语课件:Unit9 Health Care Reading.ppt
- 高中英语M7U4Language.ppt
- 高三英语课件:fashion in China and Western Country.ppt
- 高三复习语法专题——冠词的用法.ppt
- 高中英语常考动词短语归纳文档.doc
- 高中英语必修4第四单元综合测评.doc
- 高中英语必修一第二单元Reading and Speaking.ppt
- 高中英语新课标(人教版)优秀课件 选修六 1.3《Unit1 Art》(可编辑PPT课件)unit1.ppt
- C++语言程序设计课件 第06章 数组、指针与字符串.ppt
- C4-State-Machine.ppt
- CCM PFC Inductor Design with Powder Core.ppt
- CCNAS SECURITY FINAL 100% 思科安全课程final答案.doc
- Central Queensland University HRMT19021 Principles of Employment Relations Text Chapter Slides.ppt
- CE 4 - Unit 3 changing planet.ppt
- cet-6(1.2).ppt
- ch 1 self awareness.ppt
- ch00 preface.ppt
- ch02-physical.ppt
文档评论(0)