当前位置:网站首页>What is a virtual function?
What is a virtual function?
2022-07-28 03:20:00 【In the first World War, Cheng Shuo rushed】
Use of virtual functions
- yes C++ The mechanism used to implement polymorphism in ,“ Dynamic linking ”, The call of a class function is not determined at compile time , It is determined at the running time
class A
{
public:
virtual void foo0 {cout << "A::foo() is called"c<<endl;}
}
class B: public A
{
public:
virtual void foo0{ cout <<"B::foo0 is called" << endl;}
};
that , In use , We can :
A *a = new B();// The parent class pointer points to the object of the child class
a->foo();
- A constructor cannot be a virtual function
- The destructor of the base class should be a virtual function
- Friend function cannot be virtual , Because friend functions are not class members , Only class members can be virtual functions
Design patterns
- Practical application of object-oriented design principles , Encapsulation of classes , inheritance . encapsulation , Improve code reusability , Code readability and code reliability
Opening and closing principle
- Open to expansion , Turn off for changes , When demand changes , Without modifying the software entity , It can extend the function of the module , To meet new needs ;
- Software testing focuses on testing the extended new code ;
- Improve the maintainability of the software , Stronger maintainability and continuity ;
- “ Abstract constraints , Packaging changes ”
Richter's principle of substitution
- Inheritance must ensure that the properties owned by the superclass still hold in the subclass
The principle of Dependence Inversion
High level modules should not rely on low-level modules , Both should depend on abstraction ;
CIass JDshop : public Shop{
virtuall void sell0;
)
Class Customer{
void shopping(Shop *pShop)
{
cout<<Customer.name<< pShop-sell0<<endl:
}
Principle of single responsibility
Interface isolation principle
Dimitar's law
Synthetic multiplexing principle
Design patterns, behavioral
- It is used to describe the complex process control of a program at run time , That is, it describes the cooperation between multiple classes or objects to jointly complete tasks that cannot be completed by a single object .
Template pattern
- Step execution sequence of known algorithm , But the specific implementation of some steps is unknown ;
- Define the algorithm skeleton of an operation , And delay some steps of the algorithm to subclasses , So that the subclass can redefine some specific steps of the algorithm without changing the structure of the algorithm ;
class Frame
{
public:
};
边栏推荐
- 基于OpenCV的轮廓检测(3)
- Hotel VR panoramic display shooting provides more opportunities for cooperation and negotiation
- QT official example: Fridge Magnets example
- 20条心灵鸡汤唯美句子,句句温情暖心!
- 图像去噪综合比较研究
- C#实现弹出一个对话框的同时,后面的form不可用
- GNU 通用公共许可证 v2.0 GNU GENERAL PUBLIC LICENSE
- Digital twin technology drives smart factory to reduce burden and enhance operation and maintenance benefits
- 颜色的识别方法和探索 基于matlab
- redis网络模型解析
猜你喜欢

C#实现弹出一个对话框的同时,后面的form不可用

Industry insight | is speech recognition really beyond human ears?

Development and design logic of rtsp/onvif protocol easynvr video platform one click upgrade scheme

行业洞察 | 语音识别真的超过人耳朵了吗?

嵌入式分享合集22

决策树与随机森林学习笔记(1)

Web server

JVM memory layout detailed, illustrated, well written!

Tungsten Fabric SDN — BGP as a Service

基于c8t6芯片开发RC522模块实现呼吸灯
随机推荐
数据湖(十七):Flink与Iceberg整合DataStream API操作
将Helm编写的Chart推送到Harbor仓库
叶子识别 颜色的特征提取 缺陷检测等
ThreadLocal使用场景
Redis持久化机制
Win11输入法的选字框不见了怎么办?
【2022牛客多校2 K Link with Bracket Sequence I】括号线性dp
阿里云国际版邮件服务套餐购买流程
IronOCR for .NET 2022.8
《工程电磁场导论》课后习题附答案
【uni-app高级实战】手把手带你学习一个纯实战复杂项目的开发2/100
Summary of static blog building tools
Engineering Geology Practice - engineering geology problem set
Interview experience: first tier cities move bricks and face software testing posts. 5000 is enough
C WinForm development: how to add pictures to project resources
When a dialog box pops up, the following form is not available
ELS displays a random square
[acwing 1064 little king] shaped pressure DP
嵌入式开发:提示和技巧——用C进行防御性编程的最佳实践
【类的本质(Objective-C语言中)】