I have recently taken a project with another developer, and he has a certain way of initializing his references.
class Player
{
private:
Console &console;
Armor &armor1, &armor2;
Debugger &debugger;
sf::RenderWindow &window;
sf::Event &event;
public:
Player(Console &console, Armor &armor1, ...) : console(console), armor1(armor1), ... {};
}
And it's perfectly fine with me, but what if we add new stuff? Our constructor is massive, and so messy, I would like to know if there are better ways of initializing your references if you have a large project, because if we keep up with this, eventually our constructor will have more lines of code than what it actually does.
Our constructor is massive
Hum... Isn't the class too big for its own good? Perhaps it's time to revisit the design of that class. To answer the question: this initialization code is the recommended C++ way to initialize data members. See also http://stackoverflow.com/questions/6822422/c-where-to-initialize-variables-in-constructor. – Christian Garbin Jul 27 '13 at 19:42