Why does the following code skip the initialization of values of the temporary created?
Box::Box() : X1(0), Y1(0), X2(0), Y2(0), W((X2 < 0 ? -X2 : X2) - (X1 < 0 ? -X1 : X1)), H((Y2 < 0 ? -Y2 : Y2) - (Y1 < 0 ? -Y1 : Y1)) {std::cout<<"Con1";}
Box::Box(RECT B) : X1(B.left), Y1(B.top), X2(B.right), Y2(B.bottom), W((X2 < 0 ? -X2 : X2) - (X1 < 0 ? -X1 : X1)), H((Y2 < 0 ? -Y2 : Y2) - (Y1 < 0 ? -Y1 : Y1)) {std::cout<<"Con3";}
Box::Box(int x1, int y1, int x2, int y2) : X1(x1), Y1(y1), X2(x2), Y2(y2), W((X2 < 0 ? -X2 : X2) - (X1 < 0 ? -X1 : X1)), H((Y2 < 0 ? -Y2 : Y2) - (Y1 < 0 ? -Y1 : Y1)) {std::cout<<"Con2";}
Box::Box(Point UpperLeft, Point LowerRight) : X1(UpperLeft.X), Y1(UpperLeft.Y), X2(LowerRight.X), Y2(LowerRight.Y), W((X2 < 0 ? -X2 : X2) - (X1 < 0 ? -X1 : X1)), H((Y2 < 0 ? -Y2 : Y2) - (Y1 < 0 ? -Y1 : Y1)) {}
Box::~Box(){}
//Testing the default constructor.
Box B;
std::cout<<"B was constructed";
GetWindowRect(SomeWindowHandle, (LPRECT)&B);
cout<<B.W<<endl;
The above prints "Con2, Con1, B Was Constructed" but yet the values of Width(W) and Height(H) are 0! I'm not sure why both constructors were called before it even hits GetWindowRect :S This leads me to believe that when the constructor was called, the initialization of the members were skipped! Why? The stuff inbetween the braces print AND the values of X1, Y1, X2, Y2 are correct, but width and height aren't.
Is there a way to get it initialized when casted like that? I don't think I want to put initialization in the brackets.