摘要:
#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)
摘要:
#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
阅读(22)
评论(0)
推荐(0)
摘要:
#include#include#includeusing namespace std;/* 4.6.2 继承方式 公共继承 保护继承 私有继承*/class Base{public: int a;prot... 阅读全文
posted @ 2021-03-17 09:57
yub4by
阅读(20)
评论(0)
推荐(0)
摘要:
#include#include#includeusing namespace std;/* 4.6 继承 4.6.1 继承的基本语法 继承优点:减少重复代码 语法: class 子类 :继承方式 父类{} ... 阅读全文
posted @ 2021-03-17 09:56
yub4by
阅读(29)
评论(0)
推荐(0)
摘要:
#include#include#includeusing namespace std;/* 4.5.6 函数调用运算符重载 函数调用运算符()也可以重载 由于重载后使用的方式很像函数的调用,故也称为仿函数 仿函... 阅读全文
posted @ 2021-03-17 09:50
yub4by
阅读(43)
评论(0)
推荐(0)