just a heads up - i'm new to C++. I can't seem to make 2 objects reference each other. I've read about forward declarations and tried unique_ptr() as well as raw pointers, but i just can't get it to work... Some help would be really appreciated
So here's the idea (simplified): I have a Renderer class
class EventHandler;
class Renderer {
EventHandler *eventHandler;
public:
void addDrawing(sf::Drawable *);
};
and an EventHandler class
class Renderer;
class EventHandler {
Renderer *renderer;
};
Basically, i create Renderer which uses EventHandler. EventHandler then should also be able to use Renderer (call addDrawing method), but it should use the one and only instance of that Renderer. (this is important).
So currently there are 2 problems:
- when eventHandler calls addDrawing the program crashes, i'm not sure why, but my guess is that the Renderer object is not yet fully initialised, even though an address exists for it.
- when i create Renderer in EventHandler it is not the original Renderer instance, but a pointer to a new instance, as far as i understand. I need the original one.
And i know how to make all this work, by simply passing the Renderer as parameter, but i want it on a global scale, not local in EventHandler.