Implementing a basic object pool

Let's first start off by creating an object pool for a simple class that we can create multiples of:

class GameObject { private:   // Character's health   int currentHealth;   int maxHealth;    // Character's name   std::string name;  public:   GameObject();   void Initialize(std::string _name = "Unnamed",      int _maxHealth = -1);   std::string GetInfo();  };

So, this sample GameObject class contains a name of the object to identify it by and some example properties to make the class seem more game-object-like. Obviously, you can easily add more properties and the same principles apply. In this case, we have a function called Initialize, which provides both a set and reset of values for the class. Finally, I added ...

Get Game Development Patterns and Best Practices now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.