当前位置:网站首页>什么是虚函数?
什么是虚函数?
2022-07-28 02:39:00 【一战成硕冲冲冲】
虚函数的使用
- 是C++中用于实现多态的机制,“动态联编”,一个类函数的调用并不是编译时被确定的,而是在运行时刻确定
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;}
};
那么,在使用的时候,我们可以:
A *a = new B();//父类指针指向子类的对象
a->foo();
- 构造函数不能为虚函数
- 基类的析构函数应该为虚函数
- 友元函数不能为虚,因为友元函数不是类成员,只有类成员才能是虚函数
设计模式
- 面向对象设计原则的实际运用,对类的封装性,继承性。封装性,提高代码的可重用性,代码的可读性和代码的可靠性
开闭原则
- 对扩展开放,对修改关闭,当需求改变时,在不修改软件实体的前提下,可以扩展模块的功能,以此来满足新的需求;
- 软件测试时着重对于扩展的新代码进行测试;
- 提高软件的可维护性,可维护性和延续性更强;
- “抽象约束,封装变化”
里氏替换原则
- 继承必须保证超类所拥有的性质在子类中仍然成立
依赖倒置原则
高层模块不应该依赖低层的模块,两者都应该依赖于抽象;
CIass JDshop : public Shop{
virtuall void sell0;
)
Class Customer{
void shopping(Shop *pShop)
{
cout<<Customer.name<< pShop-sell0<<endl:
}
单一职责原则
接口隔离原则
迪米特法则
合成复用原则
设计模式行为型
- 用于描述程序在运行时复杂的流程控制,即描述多个类或对象之间相互协作共同完成单个对象都无法单独完成的任务。
模板模式
- 已知算法的步骤执行顺序,但某些步骤的具体实现未知;
- 定义一个操作中的算法骨架,而将算法的一些步骤延迟到子类中,使得子类可以不改变该算法结构的情况下重定义该算法的某些特定步骤;
class Frame
{
public:
};
边栏推荐
- Scheme sharing | experts gather to jointly explore accent AI speech recognition
- Es6.--promise, task queue and event cycle
- Raspberry pie development relay control lamp
- Thread Foundation
- 汇总了50多场面试,4-6月面经笔记和详解(含核心考点及6家大厂)
- PCB丝印如何摆?请查收这份手册!
- 《工程电磁场导论》课后习题附答案
- OA项目之我的审批(会议查询&会议签字)
- Intelligent industrial design software company Tianfu C round financing of hundreds of millions of yuan
- [email protected] Annotation usage
猜你喜欢

Data Lake: database data migration tool sqoop

Intelligent industrial design software company Tianfu C round financing of hundreds of millions of yuan

Why is it that when logging in, you clearly use the account information already in the database, but still display "user does not exist"?

满满干货赶紧进来!!!轻松掌握C语言中的函数
![[2022 Niuke Game 2 J question link with arithmetic progress] three part set three part / three part extreme value / linear equation fitting least square method](/img/4f/56033956739971d821637ae54be1bd.png)
[2022 Niuke Game 2 J question link with arithmetic progress] three part set three part / three part extreme value / linear equation fitting least square method

ssm整合(整合配置)

综合 案例

Embedded sharing collection 22

Brush questions every day to consolidate knowledge

Uniapp——拨打电话、发送短信
随机推荐
基于c8t6芯片开发RC522模块实现呼吸灯
Web server
ThreadLocal使用场景
MySQL index learning
【Codeforces Round #806 (Div. 4)(A~F)】
C#设置Textbox控件不可编辑
Web服务器
Stm32f407 ------- DSP learning
将Helm编写的Chart推送到Harbor仓库
Interview experience: first tier cities move bricks and face software testing posts. 5000 is enough
Data Lake: flume, a massive log collection engine
Tungsten Fabric SDN — BGP as a Service
[QNX hypervisor 2.2 user manual]9.10 pass
Comprehensive case
阿里云国际版邮件服务套餐购买流程
R 笔记 MICE
C#WinForm开发:如何将图片添加到项目资源文件(Resources)中
Random forest and integration method learning notes
Record of a cross domain problem
ELS displays a random square