当前位置:网站首页>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:
};
边栏推荐
猜你喜欢
随机推荐
Stm32f407 ------- DSP learning
Stm32f407 ------- FPU learning
Uniapp - make phone calls and send text messages
Blue Bridge Cup: the ninth - "lantern controller"
"Introduction to engineering electromagnetic field" after class exercises with answers
c#——switch case语句
会议OA项目之我的审批&&签字功能
stm32F407-------DSP学习
OA项目之我的审批(会议查询&会议签字)
Detailed tutorial of one click reinstallation of win7 system
Intelligent industrial design software company Tianfu C round financing of hundreds of millions of yuan
vba批量读取sql的create文来创建表
ELS keyboard information
Brush questions every day to consolidate knowledge
Redis群集
并发编程面试题总结
[download file] uniapp develops small programs, downloads files and saves them locally
行业洞察 | 语音识别真的超过人耳朵了吗?
Redis通信协议--RESP协议
颜色的识别方法和探索 基于matlab









