title: how to generate a unique id for each instance within a class in c++?
body: <p>I have attempted to create unique id's for all instances in my class, but this seems to be leading to errors later when trying to compile the program. this is the code i have written for the classes:</p>
  
  <pre><code>//this is GameObject.h
  class GameObject
  {
  public:
  
      int instances;
      GameObject();
      void Display();
  protected:
      int id;
  };
  
  //this is GameObject.cpp
  #include "GameObject.h"
  #include &lt;iostream&gt;
  
  using namespace std;
  
  
  GameObject::GameObject()
  {
      instances = this-&gt;id; //is this the correct way to generate the unique id?
  
  }
  </code></pre>