Quote:Original post by Mizipzor
It works now but is that the best way to solve it?
First of all, using cout to display debugging messages is bad, since cout buffers output. So either flush cout after the message, or use cerr (or clog) for debugging.
The next thing are global objects. Since the objects are available from everywhere, it is easy to create a cyclic dependency between those objects by accident. One thing to solve this is to have an init() function, that must be called before the object can be used. The constructor only initialises the internal state of the object, i.e. variables that depend in no way on other objects. So the initialisation is a two step approach, first create the object via its ctor, second initialise it via init().
(Singletons hide cyclic dependency between objects.)
Another way to manage those global objects is to put them into one single class, lets call it 'Globals'. The order of initialisation of objects in this class is determined by the standard, so you don't have to use singletons. Then there is only one instance of Globals, so you can use the objects in this class without a helper function like getInstance(). (BTW its always good to keep all global objects at one place.)
Its also possible to have no global objects at all (and no singletons). I think this will also lead to a better design. So if you can do it this way, go for it. Object dependency is like a tree. There is not a case such as the game needs the console to write messages, but the console needs the game to actually show them. You create your main class (you called it Game) either via new, or as a local object in main(). The ctor of that class then creates the other objects and so on.