当前位置:网站首页>(P13) use of final keyword
(P13) use of final keyword
2022-06-12 08:26:00 【Ordinary people who like playing basketball】
List of articles
1.final Modify function
- hold final Think it's a one size fits all approach
If you use final Modify function , Only virtual functions can be modified , This prevents the subclass from overriding the function of the parent class :
class Base
{
public:
virtual void test()
{
cout << "Base class...";
}
};
class Child : public Base
{
public:
void test() final
{
cout << "Child class...";
}
};
class GrandChild : public Child
{
public:
// Grammar mistakes , Rewriting is not allowed
void test()
{
cout << "GrandChild class...";
}
};
- There are three classes in the above code :
Base class :Base
Subclass :Child
Grandchildren :GrandChild
- test() Is a virtual function in the base class , Override this method in a subclass , But I don't want to continue to rewrite this method in my grandchildren , Therefore, in subclasses test() The method is marked final, There is only one use of this method in grandchildren .
2.final decorator
Use final Keyword decorated classes are not allowed to be inherited , In other words, this class cannot have derived classes .
- Child Class is final Decorated , therefore Child Class does not allow derived classes GrandChild Class inheritance is illegal ,Child It's a kind of broken offspring .
class Base
{
public:
virtual void test()
{
cout << "Base class...";
}
};
class Child final: public Base
{
public:
void test()
{
cout << "Child class...";
}
};
// error, Grammar mistakes
class GrandChild : public Child
{
public:
};
- link :final and override
边栏推荐
- MSTP的配置与原理
- Ankerui fire emergency lighting and evacuation indication system
- JVM学习笔记:三 本地方法接口、执行引擎
- MATLAB image processing - Otsu threshold segmentation (with code)
- FPGA implementation of right and left flipping of 720p image
- X64dbg debugging exception_ ACCESS_ VIOLATION C0000005
- Call method and apply method
- 企业为什么要实施MES?具体操作流程有哪些?
- Hands on deep learning -- image classification dataset fashion MNIST
- Webrtc adding third-party libraries
猜你喜欢

Vision Transformer | Arxiv 2205 - LiTv2: Fast Vision Transformers with HiLo Attention

DUF:Deep Video Super-Resolution Network Using Dynamic Upsampling Filters ... Reading notes

Production scheduling status of manufacturing enterprises and solutions of APS system

Vision Transformer | CVPR 2022 - Vision Transformer with Deformable Attention

What kind of sparks will be generated when the remote sensing satellite meets the Beidou navigation satellite?

ctfshow web4

What is the MES system? What is the operation process of MES system?

Hands on deep learning 18 -- model selection + over fitting and under fitting and code implementation

Hands on deep learning -- image classification dataset fashion MNIST

建立MES系统,需要注意什么?能给企业带来什么好处?
随机推荐
ctfshow web 1-2
Hands on learning and deep learning -- simple implementation of linear regression
(p27-p32) callable object, callable object wrapper, callable object binder
In depth interpretation of 5g key technologies
Installation series of ROS system (II): ROS rosdep init/update error reporting solution
Map the world according to the data of each country (take the global epidemic as an example)
Easyexcel exports excel tables to the browser, and exports excel through postman test [introductory case]
Triggers in MySQL
千万别把MES只当做工具,不然会错过最重要的东西
What scheduling rules does the APS software have? What is the exception handling scheme?
Py & go programming skills: logic control to avoid if else
Quaternion Hanmilton and JPL conventions
What is the MES system? What is the operation process of MES system?
Call method and apply method
Hands on learning and deep learning -- Realization of linear regression from scratch
The era of post MES system has come gradually
(p40-p41) transfer and forward perfect forwarding of move resources
Hands on deep learning -- implementation of multi-layer perceptron from scratch and its concise implementation
Hands on learning and deep learning -- a brief introduction to softmax regression
vm虚拟机中使用NAT模式特别说明