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

Chapter 9 Classes: A Deeper Look Part 1 东方 fdongaseu.edu.cn 0 2018, SEU. All rights reserved. 1
© 2009, SEU. All rights reserved. © 2018, SEU. All rights reserved. 1 Classes: A Deeper Look, Part 1 东方 fdong@seu.edu.cn Chapter 9

OBJECTIVES low to use a preprocessor wrapper to prevent multiple definition errors caused by including more than one copy of a header fille in a source -code file (使用预处理操作避免重复定义) o To understand class scope and accessing class members via the name of an object, a reference to an object or a pointer to an object.(访问类的成员) To define constructors with default arguments.(定义具有默认实 参的构造函数) How destructors are used to perform"termination housekeeping on an object before it is destroyed.(析构函数的使用) When they are called.(构造函数和析构函数的调用顺分 derin constructors and destructors are callled and the o which The logic errors that may occur when a public member function of a class returns a reference to private data.(访问权限引起的逻 辑错误) To assign the data members of one object to those of another object6 y default memberwise assignment.(通过成员赋值将一个 对象的数据成员赋给另一个对象的相应成员) 0 2018, SEU. All rights reserved. 2
© 2009, SEU. All rights reserved. © 2018, SEU. All rights reserved. 2 OBJECTIVES How to use a preprocessor wrapper to prevent multiple definition errors caused by including more than one copy of a header file in a source-code file. (使用预处理操作避免重复定义) To understand class scope and accessing class members via the name of an object, a reference to an object or a pointer to an object.(访问类的成员) To define constructors with default arguments.(定义具有默认实 参的构造函数) How destructors are used to perform “termination housekeeping” on an object before it is destroyed.(析构函数的使用) When constructors and destructors are called and the order in which they are called.(构造函数和析构函数的调用顺序) The logic errors that may occur when a public member function of a class returns a reference to private data.(访问权限引起的逻 辑错误) To assign the data members of one object to those of another object by default memberwise assignment.(通过成员赋值将一个 对象的数据成员赋给另一个对象的相应成员)

9.1 Introduction Preprocessor wrapper(预处理器封套) access functions(访问函数)& utility function 工具函数, also called a helper function) 类 o arguments default arguments for constructors(使用默认实参定义构造函数)包装 Destructor(析构函数) o Reference to private data 访问 °如何从类现有的对象生成新的对象? 拷贝 default memberwise assignment 0 2018, SEU. All rights reserved. 3
© 2009, SEU. All rights reserved. © 2018, SEU. All rights reserved. 3 9.1 Introduction Preprocessor wrapper(预处理器封套) access functions(访问函数) & utility function (工具函数, also called a helper function) arguments & default arguments for constructors(使用默认实参定义构造函数) Destructor(析构函数) Reference to private data 如何从类现有的对象生成新的对象? default memberwise assignment 包装 访问 拷贝 类

Topics 9.1 Introduction o 9.2 Time Class Case Study 9.3 Class Scope and accessing class members 9.4 Separating Interface from Implementation o 9.5 Access Functions and Utility Functions o 9.6 Time Class Case Study: Constructors with Default Arguments o 9.7 Destructors o 9. 8 When Constructors and destructors are called 9.9 Time Class Case Study: A Subtle Trap-Returning a Reference to a private Data Member o 9.10 Default Memberwise Assignment 0 2018, SEU. All rights reserved. 4
© 2009, SEU. All rights reserved. © 2018, SEU. All rights reserved. 4 Topics 9.1 Introduction 9.2 Time Class Case Study 9.3 Class Scope and Accessing Class Members 9.4 Separating Interface from Implementation 9.5 Access Functions and Utility Functions 9.6 Time Class Case Study: Constructors with Default Arguments 9.7 Destructors 9.8 When Constructors and Destructors Are Called 9.9 Time Class Case Study: A Subtle Trap - Returning a Reference to a private Data Member 9.10 Default Memberwise Assignment

9.2 Time Class Case Study Preprocessor wrapper(预处理器封套) 成员函数定义的两种方法 How to use class o The size of class 序解读( Textbook P370F91) 0 2018, SEU. All rights reserved. 5
© 2009, SEU. All rights reserved. © 2018, SEU. All rights reserved. 5 9.2 Time Class Case Study Preprocessor wrapper(预处理器封套) 成员函数定义的两种方法 How to use class The size of class

92 Time Class Case Study--流程 1. Edit 2,. Preprocess宏、文件包含、条件编译 3. Compile编译缙误(语法等) 4. Link 5. Load 6. Execute Runtime error(运行的增说,Ftml致命错误 logic逻辑错误 0 2018, SEU. All rights reserved. 6
© 2009, SEU. All rights reserved. © 2018, SEU. All rights reserved. 6 1. Edit 2. Preprocess 宏、文件包含、条件编译 3. Compile 编译错误(语法等) 4. Link 5. Load 6. Execute Runtime Error(运行时错误),Fatal致命错误,Logic逻辑错误 9.2 Time Class Case Study --- 流程

9.2 Time Class case stud Preprocessor Wrapper 现象:头文件被重复引用 est. cpp预处理 include结果 ∥/ah //test. cpp class af int a, class Af #include"a.h" #include"bh class af int a 1 int a class b double b:1 } int maino ∥/b.h int maino #include a h Aa class Bo Bb. Aa double b: return 0: Bb } return UR error C2011:A:class' type redefinition 0 2018, SEU. All rights reserved. 7
© 2009, SEU. All rights reserved. © 2018, SEU. All rights reserved. 7 9.2 Time Class Case Study --- Preprocessor Wrapper 现象:头文件被重复引用 // a.h class A{ int a; }; // b.h #include "a.h" class B{ double b; }; // test.cpp #include "a.h" #include "b.h" int main() { A a; B b; return 0; } class A{ int a;} class A{ int a;} class B{ double b;} int main() { A a; B b; return 0; } Test.cpp预处理include结果 error C2011: 'A' : 'class' type redefinition

92 Time Class Case Study-预处理器指令 #define #define pl 3.1415 #define flag 预处理器定义 o#ifdef /#ifndef o #else o #endif 0 2018, SEU. All rights reserved. 8
© 2009, SEU. All rights reserved. © 2018, SEU. All rights reserved. 8 9.2 Time Class Case Study --- 预处理器指令 #define #define PI 3.1415 #define FLAG 预处理器定义 #ifdef / #ifndef #else #endif

9.2 Time Class case stud 条件编译 般情况下,源程序中所有的行都参加编译;但 是有时希望其中一部分内容只在满足一定条件才 进行编译,也就是对一部分内容指定编译的条件, 这就是“条件编译”。 #ifndef flag #ifdef flag cout<<“代码1″<< endl cout<<“代码1"<<endl #endif #else cout<<“代码2”<<endl #ifdef flag #endif cout<<“代码2”<endl #endif 0 2018, SEU. All rights reserved. 9
© 2009, SEU. All rights reserved. © 2018, SEU. All rights reserved. 9 9.2 Time Class Case Study --- 条件编译 一般情况下,源程序中所有的行都参加编译;但 是有时希望其中一部分内容只在满足一定条件才 进行编译,也就是对一部分内容指定编译的条件, 这就是“条件编译” 。 #ifndef FLAG cout << “代码1” << endl; #endif #ifdef FLAG cout << “代码2” << endl; #endif #ifdef FLAG cout << “代码1” << endl; #else cout << “代码2” << endl; #endif

9.2 Time Class Case Study Preprocessor Wrapper Test. cpp预处理 include结果 ∥/ah //test. cpp #ifndef h #ifndef h #include ah #define h #define h #include"bh" class af int a; 1 class Af #endif int a. int maino } #ifndef h #endif A #define h class af int a 1 Ibh Bb #endif #includeh return 0: class bi double b] class bi double b } 0 2018, SEU. All rights reserved. 10
© 2009, SEU. All rights reserved. © 2018, SEU. All rights reserved. 10 9.2 Time Class Case Study --- Preprocessor Wrapper // a.h #ifndef A_H #define A_H class A{ int a; }; #endif // b.h #include "a.h" class B{ double b; }; // test.cpp #include "a.h" #include "b.h" int main() { A a; B b; return 0; } #ifndef A_H #define A_H class A{ int a;} #endif #ifndef A_H #define A_H class A{ int a;} #endif class B{ double b;} Test.cpp预处理include结果
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 贵州电子信息职业技术学院:常用办公技巧(PPT讲稿,主讲:刘忠华).ppt
- 计算机软件技术基础:《Visual Basic6.0 程序设计》课程教学资源(PPT课件)第1章 Visual Basic(VB)概述.ppt
- Dynamic Pricing in Spatial Crowdsourcing:A Matching-Based Approach.pptx
- 《Java Web应用开发基础》课程教学资源(PPT课件)第8章 EL、JSTL和Ajax技术.ppt
- 《计算机组装与维修》课程电子教案(PPT教学课件)第一章 计算机系统维护维修基础.ppt
- 湖南生物机电职业技术学院:《电子商务概论》课程教学资源(PPT课件)第六章 网上支付.ppt
- 清华大学出版社:《网络信息安全技术》教材电子教案(PPT课件讲稿)第2章 密码技术.ppt
- 《网络系统集成技术》课程教学资源(PPT课件讲稿)第六章 网络互联技术.ppt
- 数据库接口技术(PPT讲稿)开放式数据库联接 Open DataBase Connectivity——ODBC.ppt
- 《网络综合布线》课程教学资源(PPT讲稿)模块2 综合布线工程设计.ppt
- 《软件工程》课程教学资源(PPT课件讲稿)第4章 软件总体设计.ppt
- 华东理工大学:《Visual Basic程序设计教程》课程教学资源(PPT课件)第四讲 VB语言基础(运算符、函数和表达式).pps
- 《数据结构》课程教学资源(PPT课件讲稿)第六章 集合与字典.ppt
- 清华大学:《网络安全 Network Security》课程教学资源(PPT课件讲稿)Lecture 01 Introduction.pptx
- 安徽理工大学:《汇编语言》课程教学资源(PPT课件讲稿)第四章 汇编语言程序格式.ppt
- 《C程序设计》课程电子教案(PPT课件讲稿)第二章 基本数据类型及运算.ppt
- 浪潮公司:并行程序、编译与函数库简介、应用软件的调优.ppt
- 南京大学:《数据结构 Data Structures》课程教学资源(PPT课件讲稿)第二章 线性表.ppt
- 长春大学:《计算机应用基础》课程教学资源(PPT课件讲稿)第二章 操作系统.ppt
- 《C++语言基础教程》课程电子教案(PPT教学课件)教学资源(PPT课件)第2讲 C++语言基础.ppt
- 同济大学:《大数据分析与数据挖掘 Big Data Analysis and Mining》课程教学资源(PPT课件讲稿)Clustering Basics(主讲:赵钦佩).pptx
- 电子工业出版社:《计算机网络》课程教学资源(第五版,PPT课件讲稿)第三章 数据链路层.ppt
- 上海交通大学:《网络安全技术》课程教学资源(PPT课件讲稿)比特币(主讲:刘振).pptx
- 中国科学技术大学:《并行算法实践》课程教学资源(PPT课件讲稿)上篇 并行程序设计导论 单元II 并行程序编程指南 第七章 OpenMP编程指南.ppt
- Online Minimum Matching in Real-Time Spatial Data:Experiments and Analysis.pptx
- 《数字图像处理 Digital Image Processing》课程教学资源(各章要求及必做题参考答案).pdf
- 北京航空航天大学:Graph Search & Social Networks.pptx
- 《C程序设计》课程电子教案(PPT课件讲稿)第四章 数组和结构.ppt
- 西安电子科技大学:《信息系统安全》课程教学资源(PPT课件讲稿)第二章 安全控制原理.ppt
- 南京航空航天大学:《数据结构》课程教学资源(PPT课件讲稿)第十章 排序.ppt
- 四川大学:《计算机操作系统 Operating System Principles》课程教学资源(PPT课件讲稿)第9章 文件管理.ppt
- 《多媒体教学软件设计》课程教学资源(PPT课件讲稿)第4章 多媒体教学软件的图文演示设计.ppt
- 河南中医药大学(河南中医学院):《计算机网络》课程教学资源(PPT课件讲稿)第三章 数据链路层.pptx
- 上海交通大学:《Multicore Architecture and Parallel Computing》课程教学资源(PPT课件讲稿)Lecture 9 MapReduce.pptx
- 西安交通大学:《网络与信息安全》课程PPT教学课件(网络入侵与防范)第四章 口令破解与防御技术.ppt
- 《机器学习》课程教学资源(PPT课件讲稿)第十二章 计算学习理论 Machine Learning.pptx
- 广西外国语学院:《计算机网络》课程教学资源(PPT课件讲稿)第9章 DHCP协议(任课教师:卢豫开).ppt
- 《信息技术基础》课程教学资源(PPT课件)信息技术基础知识的内容.ppt
- 《PHP程序设计》教学资源(PPT课件讲稿)项目二 网站用户中心.ppt
- Microsoft .NET(PPT课件讲稿)Being Objects and A Glimpse into Coding.pptx