Constructor initialization-list evaluation order

The standard reference for this now appears to be 12.6.2 section 13.3:

(13.3) — Then, non-static data members are initialized in the order they were declared in the class definition (again regardless of the order of the mem-initializers).


It depends on the order of member variable declaration in the class. So a_ will be the first one, then b_ will be the second one in your example.


To quote the standard, for clarification:

12.6.2.5

Initialization shall proceed in the following order:

...

  • Then, nonstatic data members shall be initialized in the order they were declared in the class definition (again regardless of the order of the mem-initializers).

...

Tags:

C++

C++ Faq

Gcc