当前位置:网站首页>Chapter 13 Class Inheritance
Chapter 13 Class Inheritance
2022-08-11 05:46:00 【Zinxso】
This chapter includes:
Inheritance of is-a relationship
How to publicly derive one class from another
Protect access
Constructor member initialization list
Force up and down
Virtual member function
Early (static) and late (dynamic) binding
Abstract base class
Abstract base class
Pure virtual function
When and how to use public inheritance
Foreword:
Many vendors provide class libraries, which consist of class declarations and implementations, which combine data representation and class methods to provide a more complete package than function libraries.For example, a single class can provide all the resources for managing dialog boxes.Usually class libraries are provided as source code, which means that they can be modified to suit your needs.
C++ provides a better way to extend and modify classes than modify the source code, namely class inheritance.It can derive a new class from an existing class, and the derived class inherits the features and methods of the original class (base class).
The following are some of the work that can be accomplished through inheritance:
1. Functions can be added on the basis of existing classes.For example, the array class can add mathematical operations.
2, can add data to the class.For example, a string class can derive a class and add a data member that specifies the color of the string. 3. The behavior of the class method can be modified.For example, for a Passenger class that represents a service provided to airline passengers, a VipClassPassenger class that provides higher-level services can be derived.
The inheritance mechanism only needs to provide new features, and the class can be derived without accessing the source code.Therefore, for header files and compiled code that only provide class methods, new classes can still be derived from classes in the library.And you can distribute your class to others without exposing the implementation, while also allowing others to add new features to the class.
边栏推荐
猜你喜欢
随机推荐
arraylist之与linkedlist
Randomly generate uuid using rand function
字符与字符串
【Cron】学习:cron 表达式
(2) Docker installs Redis in practice (persistent AOF and RDB snapshots)
我的四核Cortex-A53学习之路
利用rand函数随机生成uuid
第10章 对象和类-2
标准模板题:采药
吃瓜教程task01 第2章 模型评估与选择
Chapter 13 Class Inheritance-1
【win10+cuda7.5+cudnn6.0安装caffe⑥】报错及处理方式
task04 Pytorch进阶训练技巧
第6章 分支语句和逻辑运算符
【网站小白】Hibernate插入数据成功,不报错,但是数据库中没有值
【动态代理】CGLIB 动态代理的使用及原理
Redis - the solution to the failure of connecting to the redis server in linux using jedis
flaks framework learning: adding variables to the URL
C语言——程序的编译与执行、宏定义详解
C语言结构体详解 (2) 结构体内存对齐,默认对齐数









