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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.