I’m attempting to write a tile engine and I have a method in one of my classes and I need a way of being able to use one loop to perform the method for all existing instances of the class, for instance if I have a GameObject called tile, and another called enemy would there be a way of calling GameObject::render for both of them without having to specify their names within the loop?
Share
You have to do some work. For instance in the constructors for your GameObject class you could add a pointer to the GameObject being created to a list. Then in your destructor you could remove the pointer to the object being destroyed from the same list. That way you have a list of pointers to all the live GameObject’s which you can loop through whenever you feel the need.