当前位置:网站首页>什么是虚函数?
什么是虚函数?
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:
};
边栏推荐
- 【SAML SSO解决方案】上海道宁为您带来SAML for ASP.NET/SAML for ASP.NET Core下载、试用、教程
- Decision tree and random forest learning notes (1)
- els 键盘信息
- 《MySQL数据库进阶实战》读后感(SQL 小虚竹)
- Web server
- 行业洞察 | 语音识别真的超过人耳朵了吗?
- Promise object
- Hotel VR panoramic display shooting provides more opportunities for cooperation and negotiation
- The applet has obtained the total records and user locations in the database collection. How to use aggregate.geonear to arrange the longitude and latitude from near to far?
- Scheme sharing | experts gather to jointly explore accent AI speech recognition
猜你喜欢

Data Lake: database data migration tool sqoop

工程地质实习-工程地质 题集

Full of dry goods, hurry in!!! Easy to master functions in C language

My approval of OA project (meeting inquiry & meeting signature)

MySQL index learning

42.js -- precompiled

mysql存储过程 使用游标实现两张表数据同步数据

QFileDevice、QFile、QSaveFile、QTemporaryFile
![[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

Design of the multi live architecture in different places of the king glory mall
随机推荐
Kubernetes-----介绍
Redis经典面试题总结
《MySQL数据库进阶实战》读后感(SQL 小虚竹)
Docker advanced -redis cluster configuration in docker container
RBD块存储设备的扩容以及缩容操作(六)
Design of the multi live architecture in different places of the king glory mall
Redis群集
方案分享 | 高手云集 共同探索重口音AI语音识别
WEB安全基础 - - -命令执行漏洞
Summary of static blog building tools
ELS keyboard information
微服务架构统一安全认证设计与实践
CAD创建组却没有组合在一起?
JVM memory layout detailed, illustrated, well written!
Pytorch 相关-梯度回传
Tungsten Fabric SDN — BGP as a Service
【下载文件】uniapp开发小程序,下载文件并保存到本地
阿里云国际版邮件服务套餐购买流程
Raspberry pie development relay control lamp
style=“width: ___“ VS width=“___“