0
member initializer list : order of evaluation
Hi We all know that order of function argument evaluation is not fixed and it is random i.e. we should not depend on this for any order. 1. Is it true for initializer list as well? OR 2. initializer list order is based on member variable orders? Above statement 2 is justified in code below. So just wanted to confirm that order is by chance this one for current compiler or is it always this one only? https://sololearn.com/compiler-playground/ccuWany1GT2U/?ref=app
2 Antworten
+ 4
https://stackoverflow.com/questions/6247595/order-of-calling-base-class-constructor-from-derived-class-initialization-list
the base class should always be initialized first, then the member classes in the order they are declared . This is so you won't have inconsistencies in your code. Then the compiler will not issue warnings.
something like:
class c: b{
m1
m2
c() : b(), m1(), m2(){}
}
class c: b{
m2
m1
c(): b(),m2(),m1(){}
}
+ 1
Thanks