东南大学:《C++语言程序设计》课程教学资源(PPT课件讲稿)Chapter 10 Classes A Deeper Look(Part 2)

Chapter 10 Classes: A Deeper Look, part 2 东方 fdong@seu.edu.cn O 2015, SEU. All rights reserved. 1
© 2009, SEU. All rights reserved. © 2015, SEU. All rights reserved. 1 Classes: A Deeper Look, Part 2 东方 fdong@seu.edu.cn Chapter 10

OBJECTIVES o To specify const (constant)objects and const member functions o To create objects composed of other objects o To use friend functions and friend classes o To use the this pointer To create and destroy objects dynamically with operators new and delete, respectively o To use static data members and member functions o 2015, SEU. All rights reserved. 2
© 2009, SEU. All rights reserved. © 2015, SEU. All rights reserved. 2 OBJECTIVES To specify const (constant) objects and const member functions. To create objects composed of other objects. To use friend functions and friend classes. To use the this pointer. To create and destroy objects dynamically with operators new and delete, respectively. To use static data members and member functions

Topics 10.1 Introduction 10.2 const(Constant)Objects and const Member Functions o 10.3 Composition: objects as members of Classes 10. 4 friend Functions and friend classes o 10.5 Using the this Pointer 10.6 Dynamic Memory Management with Operators new and delete o 10.7 static Class Members o 10.8 Data Abstraction and Information Hiding o 2015, SEU. All rights reserved. 3
© 2009, SEU. All rights reserved. © 2015, SEU. All rights reserved. 3 Topics 10.1 Introduction 10.2 const (Constant) Objects and const Member Functions 10.3 Composition: Objects as Members of Classes 10.4 friend Functions and friend Classes 10.5 Using the this Pointer 10.6 Dynamic Memory Management with Operators new and delete 10.7 static Class Members 10.8 Data Abstraction and Information Hiding

10.1 Introduction o const对象 °类的组合 composition:一个类以其他类的对象 作为成员 °友元( friend)函数:非成员函数如何访问类的私有 成员? o this指针:所有非 static函数的隐含实参 °动态内存管理:new和 delete运算符 °静态 static类成员 o 2015, SEU. All rights reserved. 4
© 2009, SEU. All rights reserved. © 2015, SEU. All rights reserved. 4 10.1 Introduction const对象 类的组合(composition): 一个类以其他类的对象 作为成员 友元(friend)函数: 非成员函数如何访问类的私有 成员? this指针: 所有非static函数的隐含实参 动态内存管理: new和delete运算符 静态static类成员

Topics 10.1 Introduction o 10.2 const( Constant)Objects and const Member Functions 10.3 Composition: Objects as Members of Classes 10.4 friend functions and friend classes o 10.5 Using the this pointer 10.6 Dynamic Memory Management with Operators new and delete o 10.7 static Class Members o 10.8 Data Abstraction and Information Hiding o 2015, SEU. All rights reserved. 5
© 2009, SEU. All rights reserved. © 2015, SEU. All rights reserved. 5 Topics 10.1 Introduction 10.2 const (Constant) Objects and const Member Functions 10.3 Composition: Objects as Members of Classes 10.4 friend Functions and friend Classes 10.5 Using the this Pointer 10.6 Dynamic Memory Management with Operators new and delete 10.7 static Class Members 10.8 Data Abstraction and Information Hiding

10.2 const(Constant)Objects and const member functions常量对象 °目的:一些对象要求是可修改的,另一些则 不希望被修改 o const Time noon 12,, 0 ●将变量和对象声明为 const可提高性能 °要求:不允许调用普通成员函数,仅能调用 noon对象的 const member function(常成 员函数) O 2015, SEU. All rights reserved. 6
© 2009, SEU. All rights reserved. © 2015, SEU. All rights reserved. 6 10.2 const (Constant) Objects and const Member Functions—常量对象 目的:一些对象要求是可修改的,另一些则 不希望被修改 const Time noon( 12, 0, 0 ); 将变量和对象声明为const可提高性能 要求:不允许调用普通成员函数,仅能调用 noon对象的const member function (常成 员函数)

10.2 const(Constant)Objects and const Member functions常成员函数 目的:通过把成员函数声明为 const,以表明它们 不修改类的成员变量 常成员函数(两处都要声明) o prototype void printUniversalO const o definition. void Time: printUniversal0 const (. J 要求: °不能修改本对象的数据成员 °不能调用本对象其它non-cons成员函数 O 2015, SEU. All rights reserved. 7
© 2009, SEU. All rights reserved. © 2015, SEU. All rights reserved. 7 10.2 const (Constant) Objects and const Member Functions—常成员函数 目的:通过把成员函数声明为const,以表明它们 不修改类的成员变量 常成员函数(两处都要声明) prototype: void printUniversal() const; definition: void Time::printUniversal() const { … } 要求: 不能修改本对象的数据成员 不能调用本对象其它non-const成员函数

10.2 const(Constant)Objects and const member functions一访问权限 OBJECT Member Function Access const const const non-const non-const const X√√ non-const non-const o 2015, SEU. All rights reserved. 8
© 2009, SEU. All rights reserved. © 2015, SEU. All rights reserved. 8 10.2 const (Constant) Objects and const Member Functions—访问权限 OBJECT Member Function Access const const √ const non-const X non-const const √ non-const non-const √

10.2 const(Constant) Objects and const Member Functions class time public Time (int =0, int =0, int =0 void setTime( int, int, int) void sethour(int ) void setMinute (int ) void setsecond(int int getHour( const; int getMinuteO const; int getSecondO const; void printUniversal0 const; void printstandardo万 P40110.13 private: int hour: int minute, int second, } o 2015, SEU. All rights reserved. 9
© 2009, SEU. All rights reserved. © 2015, SEU. All rights reserved. 9 10.2 const (Constant) Objects and const Member Functions class Time { public: Time( int = 0, int = 0, int = 0 ); void setTime( int, int, int ); void setHour( int ); void setMinute( int ); void setSecond( int ); int getHour() const; int getMinute() const; int getSecond() const; void printUniversal() const; void printStandard(); private: int hour; int minute; int second; };

10.2 const(Constant)Objects and const Member Functions void Time: test(Time &another) const minute 20 /不能修改 object printstandardo万 ∥/不能调用non- const成员函数 another minute= 20. ∥/oK,非同一 object another. sethour 6: ∥/oK 2015, SEU. All rights reserved. 10
© 2009, SEU. All rights reserved. © 2015, SEU. All rights reserved. 10 10.2 const (Constant) Objects and const Member Functions void Time::test(Time &another) const { minute = 20; // 不能修改object printStandard(); // 不能调用non-const成员函数 another.minute = 20; // OK,非同一object another.setHour(6); // OK }
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 广西医科大学:《计算机网络 Computer Networking》课程教学资源(PPT课件讲稿)Chapter 01 Introduction overview.pptx
- 《网络搜索和挖掘关键技术 Web Search and Mining》课程教学资源(PPT讲稿)Lecture 11 Probabilistic Information Retrieval.ppt
- 山东大学:《人机交互技术》课程教学资源(PPT课件讲稿)第3章 交互设备 3.5 显示设备 3.6 语音交互设备 3.7虚拟现实系统中的交互设备.ppt
- 东北大学:《可信计算基础》课程教学资源(PPT课件讲稿)第6章 TPM核心功能(主讲:周福才).pptx
- 媒体服务(PPT课件讲稿)Media Services.ppt
- 河南中医药大学(河南中医学院):《计算机网络》课程教学资源(PPT课件讲稿)第六章 应用层.pptx
- 中国科学技术大学:《计算机体系结构》课程教学资源(PPT课件讲稿)第6章 Data-Level Parallelism in Vector, SIMD, and GPU Architectures.ppt
- 南京大学:《编译原理》课程教学资源(PPT课件讲稿)第七章 运行时刻环境.ppt
- 《高级人工智能 Advanced Artificial Intelligence》教学资源(PPT讲稿)Lecture 7 Recurrent Neural Network.pptx
- 西安交通大学:《网络与信息安全》课程PPT教学课件(网络入侵与防范)第六章 网络入侵与防范——拒绝服务攻击与防御技术.ppt
- 西安电子科技大学:《计算机通信网》课程教学资源(PPT课件讲稿)第1章 概述(宋锐).ppt
- 中国科学技术大学:《嵌入式操作系统 Embedded Operating Systems》课程教学资源(PPT课件讲稿)第四讲 CPU调度(part II).ppt
- 大数据集成(PPT讲稿)Big Data Integration.pptx
- 《计算机文化基础》课程教学资源(PPT课件讲稿)第七章 计算机网络基础.ppt
- 《计算机应用基础》课程教学资源(PPT课件讲稿)第四章 电子表格软件(Excel 2003).ppt
- 四川大学:《操作系统 Operating System》课程教学资源(PPT课件讲稿)Chapter 3 Process Description and Control 3.1 What is a Process 3.2 Process States 3.3 Process Description.ppt
- 哈尔滨工业大学:《语言信息处理》课程教学资源(PPT课件讲稿)机器翻译 II Machine Translation II.ppt
- Gas Systems Modeling andSimulation with MSC.EASY5:GD Advanced Class Notes(EAS105 Course Notes).ppt
- 《计算机网络 Computer Networking》课程教学资源(PPT课件讲稿,英文版)Chapter 6 Wireless and Mobile Networks.ppt
- 《图像处理与计算机视觉 Image Processing and Computer Vision》课程教学资源(PPT课件讲稿)Chapter 08 Stereo vision.pptx
- 《网上开店实务》课程教学资源(PPT讲稿)学习情境1 网上开店创业策划.ppt
- 安徽理工大学:《Linux开发基础 Development Foundation on Linux OS》课程资源(PPT课件讲稿)Section 4 Perl programming(赵宝).ppt
- 香港理工大学:Artificial Neural Networks for Data Mining.ppt
- 《TCP/IP协议及其应用》课程教学资源(PPT课件)第1章 TCP/IP协议基础.ppt
- 清华大学:《高级计算机网络 Advanced Computer Network》课程教学资源(PPT课件讲稿)Lecture 1 Introduction.pptx
- 香港浸会大学:C++ as a Better C; Introducing Object Technology.ppt
- 大庆职业学院:《计算机网络技术基础》课程教学资源(PPT课件讲稿)第2章 数据通信的基础知识.ppt
- The Art of Function Design -Measure and RKHS.ppt
- 《计算机网络与因特网》课程教学资源(PPT课件)Part VII 广域网(简称WAN), 路由, 和最短路径.ppt
- 三维计算机视觉 3D computer vision(基于卡尔曼滤波的运动结构).pptx
- 河南中医药大学(河南中医学院):《计算机文化》课程教学资源(PPT课件讲稿)第七章 数据库技术(主讲:王哲).pptx
- 《单片机原理及应用》课程教学资源(PPT课件讲稿)第14章 单片机应用系统抗干扰与可靠性设计.ppt
- 北京航空航天大学:《数据挖掘——概念和技术(Data Mining - Concepts and Techniques)》课程教学资源(PPT课件讲稿)Chapter 01 Introduction.ppt
- 《单片机应用系统设计技术》课程教学资源(PPT课件讲稿)第7章 单片机外部扩展资源及应用.ppt
- 香港浸会大学:MPI - Communicators(PPT讲稿).ppt
- 电子工业出版社:《计算机网络》课程教学资源(第五版,PPT课件讲稿)第九章 无线网络.ppt
- 中国铁道出版社:《局域网技术与组网工程》课程教学资源(PPT课件讲稿)第2章 网络工程系统.ppt
- 自动语音识别(PPT讲稿)Automatic Speaker Recognition.pptx
- 南京大学:《编译原理》课程教学资源(PPT课件讲稿)第三章 词法分析.pptx
- 上海交通大学:人工智能的历史和启示——人机对弈作为案例.ppt