Original Post
For my current project I have an Entity class that all game objects are inherited from.
I also have an EntityManager class that keeps a list of pointers to all the game objects created. The idea being that this list will be used for updating and drawing all game objects to the screen.
I find myself struggling to find the best way to design all of this.
How do I make sure all game objects are added to the EntityManager list?
How do I make sure that when an object is deleted, all other game objects that might have a pointer to said object are not now referencing deallocated memory?
During cleanup I delete all the Entity objects in EntityManager, and therefore they all need to be heap objects created with the new keyword. How do I make sure none of the pointers point to a stack object?
Right now I am doing this project alone, and ultimately the easy way out to most of these questions is for me to just remember things and don't make mistakes.
"Just dont forget that all entity objects need to be made using new."
I also have an EntityManager class that keeps a list of pointers to all the game objects created. The idea being that this list will be used for updating and drawing all game objects to the screen.
I find myself struggling to find the best way to design all of this.
How do I make sure all game objects are added to the EntityManager list?
How do I make sure that when an object is deleted, all other game objects that might have a pointer to said object are not now referencing deallocated memory?
During cleanup I delete all the Entity objects in EntityManager, and therefore they all need to be heap objects created with the new keyword. How do I make sure none of the pointers point to a stack object?
Right now I am doing this project alone, and ultimately the easy way out to most of these questions is for me to just remember things and don't make mistakes.