With the 2016 tutorial series, I've really only come across one common issue and that's in the FartAnnoyed tutorials. In this series, chili initializes a RectF structure by calling one constructor from another. The common issue among first time watchers is missing the placement of the call, see below.
Most seen incorrect code on forum from this series
Code: Select all
RectF::RectF(const Vec2 & topLeft, const Vec2 & bottomRight)
{
RectF(topLeft.x, bottomRight.x, topLeft.y, bottomRight.y);
}
RectF::RectF(const Vec2 & topLeft, float width, float height)
{
RectF(topLeft, topLeft + Vec2(width, height));
}
The code is meant to forward the values to the RectF constructor taking four floats, but is actually happening is that constructor is being called to create a temporary and then deleted because it isn't being assigned to anything. The correct version should be:
Code: Select all
RectF::RectF( Vec2 & topleft, Vec2 & bottomright )
:
RectF( topleft.x, bottomright.x, topleft.y, bottomright.y )
{
}
RectF::RectF( Vec2 & topleft, float height, float width )
:
RectF( topleft, topleft + Vec2( width, height ) )
{
}
You should notice that the call to the next constructor happens after : and before { }. This space is called the class initializer list. This is used to initialize data members of the class. The { } portion of the constructor is the function body which is like any other function body other than not being able to return values.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com