------ Key inherit summary

Inheritance (parent of private property, subclasses are not accessible; it was inherited, sizeof time as well as its size, because the compiler is hidden)
subclass inherits the public: public property or method in the parent class or subclass public, protected or protected.
Subclass inherits protection: public properties or methods of the parent class into a subclass protection, protection or protection.
Subclass private inheritance: public properties or methods of the parent class become private in a subclass to protect proprietary.
Summary: The inheritance way can be understood as a subclass of least privilege, this privilege over the properties and methods, to pull back the minimum permissions, eg: protection of inheritance, the parent of all public back to proteste
(1) construction and destructor will not be inherited
(2) sub-categories appear with the same name as the parent class property, the default is to use the principle of proximity. Want to access the parent class, you can add scope. (Of the same name function the same way)

多继承:子类有两个以上的父类(class A:public class B,public class C)
多继承会产生的问题:二义性问题,即两个父类中有相同的属性;
解决方法:加父类的作用域来具体访问哪个父类的属性;



菱形继承:多继承模型上,两个父类来自在同一个爷类。形成菱形;
菱形继承会产生的问题:二义性问题
解决方法:两个父类虚继承爷类,自己形成虚基类;(二义性消失)
虚基类结构:vbptr 虚基类指针(两个父类都有一个)-----指向自己的的虚基类表,找到各自指向唯一属性的偏移量。
Published 38 original articles · won praise 13 · views 4329

Guess you like

Origin blog.csdn.net/YanWenCheng_/article/details/103946958