I had an annoying problem with the initailizer list that took me ages to discover and fix.
I don't fully understand why it didn't work, stepping through i could see it working. it would initialise the top constructor, but then it would reset because it would return to the previous constructor body.
some clarification to help me understand would be appreciated
here are the two versions.
Updated:
Code: Select all
Rect::Rect(int left, int right, int top, int bottom)
:
left(left),
right(right),
top(top),
bottom(bottom)
{
}
Rect::Rect(Vec2 & topleft, Vec2 & botright)
:
Rect(int(topleft.x), int(botright.x), int(topleft.y), int(botright.y))
{
}
Rect::Rect(Vec2 & topLeft, int width, int height)
:
Rect(topLeft, Vec2((topLeft.x + width), (topLeft.y + height)))
{
}
Code: Select all
Rect::Rect(int left, int right, int top, int bottom)
:
left(left),
right(right),
top(top),
bottom(bottom)
{
}
Rect::Rect(Vec2 & topleft, Vec2 & botright)
{
Rect(int(topleft.x), int(botright.x), int(topleft.y), int(botright.y))
}
Rect::Rect(Vec2 & topLeft, int width, int height)
{
Rect(topLeft, Vec2((topLeft.x + width), (topLeft.y + height)))
}