Posts

Showing posts from August, 2018

A Small Look at Constructor Data-member Evaluation Order (C++)

I have a habbit of regularly going back to basics and doing a form of high-speed review of whatever in relation to general programming. I tend to forget small details, but if left for too long, these items add up and people can end up subconsiously forgetting entire topics and/or functionalities. One interesting thing that may be a small and rather overlooked feature of C++ would be the way the constructor, or rather the compiler would package data memebers of a constructor in the order the class member variables are listed. Ctor::Ctor( GameType& gtRef ) : randomizer( rand() ), gameObj0(x(randomizer), y(randomizer)), gameObj1(x(randomizer), y(randomizer)) { flag = false; }  In the above example, everything seems fine, however in the class body, there was something wrong when debugging the issue. private: MainWindow& wnd; Graphics gfx; // Game Objects GameObject gameObj0; GameObject