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

27th Feb 2025, 7:42 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
2 Respuestas
+ 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(){} }
28th Feb 2025, 12:20 AM
Bob_Li
Bob_Li - avatar
+ 1
Thanks
28th Feb 2025, 4:24 AM
Ketan Lalcheta
Ketan Lalcheta - avatar