For this code:
struct Vec2 {
float x,y;
Vec2():x(0),y(0) {
printf( "Construct Vec2 %f %f",x,y );
}
};
struct Rectangle {
union {
struct { float x,y; };
Vec2 pos;
};
union {
struct { float w,h; };
Vec2 size;
};
RectF(){
printf( "construct RectF %f %f %f %fn", x,y,w,h );
}
}
int main() {
Rectangle r;
}
I was very surprised to learn that the default constructors for Vec2
are not triggered for the Vec2
s that are inside the union
s inside the Rectangle
I was very surprised by that wonder why that is?