Actually, the compiler always initializes the variables in the declaration order, even if you write the initializers in a different order. Therefore, if you do not record initializations in the declaration order, the order of your initializers does not correspond to the initialization order, which can lead to subtle errors if the initialization is dependent on each other.
For example, consider the code
Test(): b(42), a(b) {}
This is a mistake because a initialized to b , but it looks fine. If you write it in the declaration order (which is the initialization order), the error becomes apparent:
Test(): a(b), b(42) {}
Note that the error can also be more subtle than that, for example, to represent a and b types of classes that output something in their constructor; then with the “wrong” order you think that the output of b should appear before a , when in reality the opposite happens. If the output of a , which appears first, leads to an invalid file, which will also lead to an error, but the compiler will not be able to notice the problem if the constructors are in a different translation unit (except that the compiler cannot know if the reordering is not an error ) Therefore, it is reasonable that the compiler simply warns about each instance of an inconsistent order.
celtschk Aug 31 '12 at 21:08 2012-08-31 21:08
source share