In my C++ project, I have an Engine
class and an Object
class.
My issue lies with how my instances of Object
are created. Currently this is done through the use of a CreateObject(parameters)
function in the Engine
class. This adds a new instance of Object
to an std::vector
of Object
instances.
I want to maintain this list of instances of Object
in my Engine
class, but without the need for the CreateObject(parameters)
function. My reason for this is so that I can create new classes that can inherit from Object
but still be added to this list. The reason for this list is so that (in Engine
) I can iterate through every Object
instance that has been created.
This would ultimately mean that I create my Object
instances with something like Object newObject = Object(parameters);
, but still have the Engine
class maintain a list of all Object
instances, without the need for Object
to reference the instance of Engine
or the list to add itself to this list (as in the instance of Object
should not know about the list it is in). Can this be done?