C ++多继承顺序 [英] C++ multiple inheritance order
问题描述
我想了解继承顺序在C ++的影响..我在网上看,但我找不到一个清楚和足够的答案...
I'm trying to understand the affect of inheritance order in C++.. I looked online, but I couldn't find a clear and sufficient answer...
因此,为了这个问题,假设有两个类:B类和C类。
So, for the sake of the question, assume there are 2 classes: class B and class C.
现在,定义:
class A1 : public B, public C{ ... };
class A2 : public C, public B{ ... };
A1和A2之间有什么区别?
What is the difference between A1 and A2?
非常感谢。
推荐答案
派生顺序仅与确定顺序
The order of derivation is relevant only to determine the order of default initialization by constructors and cleanup by destructors.
除非由构造函数(12.6.2)初始化的语义所指定,导出的顺序并不重要,清理(cleanup) 12.4)和存储布局(9.2,11.1)。 - end note](§10.1/ 2)
The order of derivation is not significant except as specified by the semantics of initialization by constructor (12.6.2), cleanup (12.4), and storage layout (9.2, 11.1). — end note ]" (§10.1/2)
从IBM的C ++文档:多重继承
From IBM's C++ documentation: Multiple inheritance
这篇关于C ++多继承顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!