基类子对象可以具有零大小。
不属于位域的两个对象可能拥有相同的地址(如果一个对象是另一个对象的子对象,或者至少有一个是空的基类子对象,并且他们的类型不同); 否则,他们应该在不同的地址上。
Two objects that are not bit-fields may have the same address if one is a subobject of the other, or if at least one is a base class subobject of zero size and they are of different types;
当构造、拷贝、赋值或撤销一个派生类对象时,也要构造、拷贝、赋值或撤销那些基类的子对象。
When we construct, copy, assign, or destroy an object of derived type, we also construct, copy, assign, or destroy those base-class subobjects.
子对象多重继承自多个基类,每个基类都有虚函数,那么子类对象的内存布局是什么样的?
A function that is virtual in a base class is implicitly virtual in its derived classes. When a derived class overrides a virtual, the parameters in the base and derived classes must match exactly.
子对象多重继承自多个基类,每个基类都有虚函数,那么子类对象的内存布局是什么样的?
A function that is virtual in a base class is implicitly virtual in its derived classes. When a derived class overrides a virtual, the parameters in the base and derived classes must match exactly.
应用推荐