上一页 1 ··· 80 81 82 83 84 85 86 87 88 ··· 91 下一页
摘要: #include#include#includeusing namespace std;/* 4.7.3 纯虚函数和抽象类 在多态中,通常父类中虚函数的实现是毫无意义的,主要都是调用子类重写的内容,因此可以将虚函数改为纯虚函数 ... 阅读全文
posted @ 2021-03-18 10:37 yub4by 阅读(24) 评论(0) 推荐(0) 编辑
摘要: #include#include#includeusing namespace std;/* 4.7.2 多态案例--计算器类 案例描述: 分别利用普通写法和多态技术,设计实现两个操作数进行运算的计算器类 ... 阅读全文
posted @ 2021-03-18 10:37 yub4by 阅读(55) 评论(0) 推荐(0) 编辑
摘要: #include#include#includeusing namespace std;/* 4.7 多态 4.7.1 多态的基本概念 多态分两类: 静态多态:函数重载和运算符重载属于静态多态,复用函数名 ... 阅读全文
posted @ 2021-03-17 15:48 yub4by 阅读(24) 评论(0) 推荐(0) 编辑
摘要: #include#include#includeusing namespace std;/* 4.6.8 菱形继承 两个派生类继承同一个基类,又有某个类同时继承者两个派生类,这种继承被称为菱形继承,或者钻石继承 例如:羊继... 阅读全文
posted @ 2021-03-17 13:33 yub4by 阅读(24) 评论(0) 推荐(0) 编辑
摘要: #include#include#includeusing namespace std;/* 4.6.7 多继承语法 实际开发中不建议使用多继承 多继承可能引发父类中有同名成员出现,需要加作用域区分 class ... 阅读全文
posted @ 2021-03-17 13:32 yub4by 阅读(17) 评论(0) 推荐(0) 编辑
摘要: #include#include#includeusing namespace std;/* 4.6.6 继承同名静态成员处理方式 静态成员和非静态成员出现同名,处理方式一致: 访问子类同名成员,直接访问即可 ... 阅读全文
posted @ 2021-03-17 13:31 yub4by 阅读(29) 评论(0) 推荐(0) 编辑
摘要: #include#include#includeusing namespace std;/* 4.6.5 继承同名成员处理方式 访问子类同名成员,直接访问即可 访问父类同名成员,需要加作用域*/class Base{publi... 阅读全文
posted @ 2021-03-17 10:00 yub4by 阅读(22) 评论(0) 推荐(0) 编辑
摘要: #include#include#includeusing namespace std;/* 4.6.4 继承中构造和析构顺序 子类继承父类后,当创建子类对象时,也会调用父类的构造函数 结论:先构造父类在构造子类,析构顺序与构... 阅读全文
posted @ 2021-03-17 09:59 yub4by 阅读(18) 评论(0) 推荐(0) 编辑
摘要: #include#include#includeusing namespace std;/* 4.6.3 继承中的对象模型*/class Base{public: int a;protected: int b;private: int ... 阅读全文
posted @ 2021-03-17 09:58 yub4by 阅读(19) 评论(0) 推荐(0) 编辑
摘要: #include#include#includeusing namespace std;/* 4.6.2 继承方式 公共继承 保护继承 私有继承*/class Base{public: int a;prot... 阅读全文
posted @ 2021-03-17 09:57 yub4by 阅读(16) 评论(0) 推荐(0) 编辑
上一页 1 ··· 80 81 82 83 84 85 86 87 88 ··· 91 下一页