上一页 1 ··· 80 81 82 83 84 85 86 87 88 ··· 91 下一页
摘要: #include#include#includeusing namespace std;/* 4.7.5 虚析构和纯虚析构 多态使用时,如果子类中有属性开辟到堆区,那么父类指针在释放时无法调用到子类的析构代码 解决方式:将父类... 阅读全文
posted @ 2021-03-18 10:38 yub4by 阅读(31) 评论(0) 推荐(0)
摘要: #include#include#includeusing namespace std;/* 4.7.2 多态案例--计算器类 案例描述: 分别利用普通写法和多态技术,设计实现两个操作数进行运算的计算器类 ... 阅读全文
posted @ 2021-03-18 10:37 yub4by 阅读(68) 评论(0) 推荐(0)
摘要: #include#include#includeusing namespace std;/* 4.7.3 纯虚函数和抽象类 在多态中,通常父类中虚函数的实现是毫无意义的,主要都是调用子类重写的内容,因此可以将虚函数改为纯虚函数 ... 阅读全文
posted @ 2021-03-18 10:37 yub4by 阅读(33) 评论(0) 推荐(0)
摘要: #include#include#includeusing namespace std;/* 4.7.4 多态案例2--制作饮品 案例描述: 制作饮品的大致流程为:煮水 - 冲泡 - 倒入杯中 - 加入辅料 ... 阅读全文
posted @ 2021-03-18 10:37 yub4by 阅读(22) 评论(0) 推荐(0)
摘要: #include#include#includeusing namespace std;/* 4.7 多态 4.7.1 多态的基本概念 多态分两类: 静态多态:函数重载和运算符重载属于静态多态,复用函数名 ... 阅读全文
posted @ 2021-03-17 15:48 yub4by 阅读(28) 评论(0) 推荐(0)
摘要: #include#include#includeusing namespace std;/* 4.6.8 菱形继承 两个派生类继承同一个基类,又有某个类同时继承者两个派生类,这种继承被称为菱形继承,或者钻石继承 例如:羊继... 阅读全文
posted @ 2021-03-17 13:33 yub4by 阅读(30) 评论(0) 推荐(0)
摘要: #include#include#includeusing namespace std;/* 4.6.7 多继承语法 实际开发中不建议使用多继承 多继承可能引发父类中有同名成员出现,需要加作用域区分 class ... 阅读全文
posted @ 2021-03-17 13:32 yub4by 阅读(25) 评论(0) 推荐(0)
摘要: #include#include#includeusing namespace std;/* 4.6.6 继承同名静态成员处理方式 静态成员和非静态成员出现同名,处理方式一致: 访问子类同名成员,直接访问即可 ... 阅读全文
posted @ 2021-03-17 13:31 yub4by 阅读(34) 评论(0) 推荐(0)
摘要: #include#include#includeusing namespace std;/* 4.6.5 继承同名成员处理方式 访问子类同名成员,直接访问即可 访问父类同名成员,需要加作用域*/class Base{publi... 阅读全文
posted @ 2021-03-17 10:00 yub4by 阅读(26) 评论(0) 推荐(0)
摘要: #include#include#includeusing namespace std;/* 4.6.4 继承中构造和析构顺序 子类继承父类后,当创建子类对象时,也会调用父类的构造函数 结论:先构造父类在构造子类,析构顺序与构... 阅读全文
posted @ 2021-03-17 09:59 yub4by 阅读(24) 评论(0) 推荐(0)
上一页 1 ··· 80 81 82 83 84 85 86 87 88 ··· 91 下一页