One more time: what is the exact order of constructors in a multiple and/or virtual inheritance situation?
The very first constructors to be executed are the virtual base classes anywhere in the hierarchy. They are executed in the order they appear in a depth-first left-to-right traversal of the graph of base classes, where left to right refer to the order of appearance of base class names. After all virtual base class constructors are finished, the construction order is generally from base class to derived class. The details are easiest to understand if you imagine that the very first thing the compiler does in the derived class’s ctor is to make a hidden call to the ctors of its non-virtual base classes (hint: that’s the way many compilers actually do it). So if class D inherits multiply from B1 and B2, the constructor for B1 executes first, then the constructor for B2, then the constructor for D. This rule is applied recursively; for example, if B1 inherits from B1a and B1b, and B2 inherits from B2a and B2b, then the final order is B1a, B1b, B1, B2a, B2b, B2, D. Note that the order B1 an
Related Questions
- What are the exact steps I need to do and the exact costs, time frame and who do I contact to move to the UK?
- One more time: what is the exact order of constructors in a multiple and/or virtual inheritance situation?
- What is the exact order of destructors in a multiple and/or virtual inheritance situation?