class Base
{
public:
int temp1;
int temp2;
Base();
Base(const Base&):temp2(10), temp1(20) {};
};
main()
{
Base b1;
Base b2 = b1;
}
Here, copy constructor of Base class contructs Base object with temp1 and temp2 out of order. The program runs perfectly fine with correct values assined to members of b2.
I was under the impression that if initialization list initializes members out of order, then that will not work. What exactly should happen here?
It is just a warning to you as the programmer that although you are ostensibly initializing temp2 before temp1 (because of the order in which you specified them in the initializer list), the compiler will nonetheless initialize them in a different order.
It is simply a warning to you: hey, do you really mean to initialize them in this order?
In your case it does not matter, but in some cases order of initialization can matter.
It is good practice in any event to order them in the same sequence they are declared to avoid the warning. That way you don't have to start figuring out which warnings are ok and which are bad.