I have a tricky C++ question: When you have a constructor initialization list with delegated constructors, what is the list execution order?
There exist two conflicting standard rules here:
1.) The constructor initialization list gets executed NOT by the list order but by the declaration order of the items.
2.) Delegated constructors in the constructor initialization list always get called before the "mother constructor" is executed.
Which rule is superior? (since a constructor is a class item too) Why this is important: assume the delegated constructor re-inits an item already initialized by the "mother constructor" or vice versa.
§12.6.2/6 says
If a mem-initializer-id designates the constructor’s class, it shall be the only mem-initializer... Once the target constructor returns, the body of the delegating constructor is executed.
So there's no conflict, since you can't initialise anything before you delegate a constructor. Delegating a constructor simply calls that constructor, the target constructor's initialiser list is run, the target constructor runs, and then the principal constructor runs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With