In the following code, when the ctor of X
is called will the ctor of A
or B
be called first? Does the order in which they are placed i
Initialization is always in the order that the class members appear in your class definition, so in your example a
, then b
.
There is a sequence point between the initialization of each member and you can pass a reference to a yet-to-be initialized member into the constructor of a class member but you would only be able to use it in limited ways (such as taking its address to form a pointer), other uses may well cause undefined behaviour.
Destruction of class members always happens in the reverse order of construction.
Order of initialization of bases and members is defined in 12.6.2 [class.base.init]/5.