《The C++ Programming Language》课程教学资源(PPT课件讲稿)Lecture 06 OOP with Templates

The c ++ Programming Language Lecture 6 OOP With Templates
The C++ Programming Language Lecture 6: OOP with Templates

Basic Concepts and Syntaxes
Basic Concepts and Syntaxes

Template u Original name-Parameterized Types Parameterized-Abstracted data type information from Implementation Type- For every class template or function template, there are different features and characters when bound to different data pes, they act like a type Template generate a function or class automatically according to the value or type user specified string, vector, list are all class templates, and we will implement our template in this lecture
Template ◼ Original name – Parameterized Types ◼ Parameterized – Abstracted data type information from implementation ◼ Type – For every class template or function template, there are different features and characters when bound to different data types, they act like a type ◼ Template generate a function or class automatically, according to the value or type user specified ◼ string, vector, list are all class templates, and we will implement our template in this lecture

Starting Point-the binary tree class Piglet Root Eeyore RoO Left child Right child Chris K anga Pooh Tigger Operations that need to be provided Insert, remove Find, clear Print(preorder, inorder, postorder) Preorder: Piglet, Eeyore, Chris, Kanga, Roo, Pooh, Tigger Inorder: Chris, Eeyore, Kanga, Piglet, Pooh, Roo, Tigger Postorder: Chris Kanga, Eeyore, pooh, Tigger, roo piglet
Starting Point – the binary tree class ◼ Operations that need to be provided ◼ Insert, remove ◼ Find, clear ◼ Print (preorder, inorder, postorder) – Preorder: Piglet, Eeyore, Chris, Kanga, Roo, Pooh, Tigger – Inorder: Chris, Eeyore, Kanga, Piglet, Pooh, Roo, Tigger – Postorder: Chris, Kanga, Eeyore, Pooh, Tigger, Roo, Piglet Piglet Roo Pooh Tigger Right child Eeyore Chris Kanga Left child Root

The binary tree class 2 classes BinaryTree- storing only one pointer pointing to the root BINode-storing the value of node and links to left and right childs We provide a non-template BTNode class declaration class string BTNode p pI rivate string m szVal nt m iCnt string btNode* Child string btnode* rchild };
The binary tree class ◼ 2 classes ◼ BinaryTree – storing only one pointer pointing to the root ◼ BTNode – storing the value of node and links to left and right childs ◼ We provide a non-template BTNode class declaration class string_BTNode { public: //… private: string m_szVal; int m_iCnt; string_BTNode* lchild; string_BTNode* rchild; };

Parameterized Types u Without Template, we have to implement multiple BTNode classes with different names and data types For those insertion, deletion and traversing ops, their mechanism won't change when node data type changes thus are type- independent? a We extract the "type-dependent"parts and parameterize them
Parameterized Types ◼ Without Template, we have to implement multiple BTNode classes with different names and data types ◼ For those insertion, deletion and traversing ops, their mechanism won’t change when node data type changes, thus are “typeindependent” ◼ We extract the “type-dependent” parts and parameterize them

Parameterized Types(cont) template< typename valtype class btnode //forward declaration template typename valtype class btnode //class definition public The valtype in Class template is used as a space reserver pI rivate valtype m Val a It's a type parameter that int m icnt could replace any built-in BTNode* Child BTNode* rchild type or user-defined type }; while running
Parameterized Types (cont.) template class BTNode; //forward declaration //… template class BTNode //class definition { public: //… private: valtype m_Val; int m_iCnt; BTNode* lchild; BTNode* rchild; }; ◼ The valtype in class template is used as a space reserver ◼ It’s a type parameter that could replace any built-in type or user-defined type while running

Parameterized Types(cont) template typename elemtype> class Binary Tree //forward declaration template typename valtype class btnode public pI rivate friend class binary Tree
Parameterized Types (cont.) template class BinaryTree; //forward declaration template class BTNode { public: //… private: //… friend class BinaryTree; };

Parameterized Types(cont) u To generate entity class from the class template, real types should be provided in the template parameter list(<>) which the type parameter would bind to ■ Usage BTNode< int bti BTNode< string btS a bti and bts are different objects from different classes
Parameterized Types (cont.) ◼ To generate entity class from the class template, real types should be provided in the template parameter list(<>) which the type parameter would bind to ◼ Usage BTNode bti; BTNode bts; ◼ bti and bts are different objects from different classes

Parameterized Types(cont) u Definition of class BinaryTree template*m root a When we need to add template parameter list after the class template? a Except in the definition of class template and its member functions
Parameterized Types (cont.) ◼ Definition of class BinaryTree template class BinaryTree { public: //… private: //… BTNode* m_root; }; ◼ When we need to add template parameter list after the class template? ◼ Except in the definition of class template and its member functions
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 武汉科技大学中南分校:Windows 2000/XP网络组建与系统管理(系统安装,李燕).ppt
- 电子科技大学:《面向对象程序设计语言C++》课程教学资源(PPT课件讲稿)第五章 构造数据类型.ppt
- 《C语言程序设计》课程电子教案(PPT教学课件)第三章 分支结构.ppt
- 计算机维护与维修(PPT课件讲稿)第十二章 笔记本电脑维护维修.ppt
- 西安电子科技大学:《微机原理与接口技术》课程教学资源(PPT课件讲稿)第四章 汇编语言程序设计(主讲:王晓甜).pptx
- 厦门大学计算机科学系:《大数据技术原理与应用》课程教学资源(PPT课件)第12章 数据可视化.ppt
- 《计算机操作系统》课程教学资源(PPT讲稿)Windows 2003的安全.ppt
- 《计算机图形学》课程教学资源(PPT课件讲稿)Chapter 5 Attributes of Graphics Primitives.pptx
- 《计算机原理及应用》课程教学资源(PPT课件讲稿)第9章 单片机I/O接口扩展技术.pptx
- 《Access 2013数据库技术及应用》课程教学资源(PPT课件讲稿)第12章 VBA模块设计.ppt
- 清华大学:智能弹性重叠网关键技术研究(PPT讲稿,指导老师:李衍达).ppt
- 中国科学技术大学:《数据结构及其算法》课程PPT教学课件(Data Structure and Algorithm)第4章 栈和队列(主讲:刘东).pptx
- 北京科技大学:《物联网工程》课程教学资源(PPT课件讲稿)课程介绍.ppt
- 《电脑组装与维护实例教程》教学资源(PPT课件讲稿)第4章 输入输出设备介绍及选购.ppt
- 深圳大学:Learning 3D mesh segmentation and labeling(PPT讲稿).ppt
- 沈阳理工大学:《大学计算机基础》课程教学资源(PPT课件讲稿)第3章 办公软件 3.2 电子表格软件Excel 2010.ppt
- 对外经济贸易大学:《电子商务概论》期末考试试卷(部分含答案).pptx
- 清华大学:Pass-Join(A Partition based Method for Similarity Joins).pptx
- 《信息安全概论》课程教学资源(PPT课件讲稿)第九章 计算机软件的安全性.ppt
- 合肥工业大学:《数据库系统》课程教学资源(PPT课件讲稿)数据库编程 ACCESS、MYSQL、Oracle(张国富)第一章 绪论.ppt
- 厦门大学:《分布式数据库》课程教学资源(PPT课件讲稿)专题一 分布式数据库介绍.ppt
- 中国科学技术大学:《计算机体系结构》课程教学资源(PPT课件讲稿)第6章 Data-Level Parallelism in Vector, SIMD, and GPU Architectures.pptx
- 清华大学:无线网和移动网(PPT课件讲稿)Mobile and wireless network.pptx
- 广西医科大学:《计算机网络 Computer Networking》课程教学资源(PPT课件讲稿)Chapter 02 Network Classification.pptx
- 《电脑组装与维护实例教程》教学资源(PPT课件讲稿)第5章 多媒体设备介绍及选购.ppt
- 《网络算法学》课程教学资源(PPT课件讲稿)第三章 实现原则.ppt
- 《数据结构》课程教学资源:实践教学大纲.doc
- 《数据结构》课程教学资源(PPT课件讲稿)第七章 图 Graph.ppt
- 四川大学:《操作系统 Operating System》课程教学资源(PPT课件讲稿)Chapter 3 Process Description and Control 3.4 Process Control 3.5 Execution of the Operating System 3.6 Unix SVR4 Process Management 3.7 Linux Process management system calls.ppt
- 大连理工大学:《计算机网络》课程教学资源(PPT课件讲稿)Chapter 2 应用层 application layer.ppt
- 3D Reconstruction from Images:Image-based Street-side City Modeling.ppt
- 《数据结构》课程教学资源(PPT课件讲稿)第七章 图及其应用.ppt
- 香港城市大学:基序检测的随机化算法(PPT讲稿)Randomized Algorithm for Motif Detection.ppt
- 《计算机组装与维护》课程教学资源(PPT课件讲稿)第9章 BIOS设置(设置BIOS).ppt
- 《Introduction to Java Programming》课程PPT教学课件(Sixth Edition)Chapter 16 Applets and Multimedia.ppt
- 上海交通大学:《挖掘海量数据集 Mining Massive Datasets》课程教学资源(PPT讲稿)Lecture 06 搜索引擎 Search Engines.ppt
- 《计算机系统安全》课程教学资源(PPT课件讲稿)第二章 黑客常用的系统攻击方法.ppt
- 《C语言程序设计》课程教学资源(PPT课件讲稿)第8章 结构体、共用体与枚举类型.ppt
- 香港浸会大学:Introduction to Linux and PC Cluster.ppt
- 南京大学:《计算机图形学》课程教学资源(PPT课件讲稿)第7讲 图元填充与裁剪算法.pptx