Why should I initialize member variables in the order they’re declared in?

The reason is because they’re initialized in the order they’re declared in your class, not the order you initialize them in the constructor and it’s warning you that your constructor’s order won’t be used.

This is to help prevent errors where the initialization of b depends on a or vice-versa.

The reason for this ordering is because there is only one destructor, and it has to pick a “reverse order” to destroy the class member. In this case, the simplest solution was to use the order of declaration within the class to make sure that attributes were always destroyed in the correct reverse order.

Leave a Comment