title: C++ Vector of classes, can't push_back inside constructor of said class
body: <p>So here is my problem, I want a vector of objects of a certain class that I can then pass to other classes for use.</p>
  
  <p>I want the Vector to add an instance of the class within the constructor of that class. So I've set up a static vector inside the class members and in the constructor I want to try and push_back(this) if that makes any sense.</p>
  
  <p>There are 2 classes currently at work, one is the event handler class that creates an instance of "Obstacle" class (the class I want a vector of) every time there is a left click.</p>
  
  <p>(I have omitted irrelevant bits of code)</p>
  
  <pre><code>class MyEventReceiver: public IEventReceiver
  {
  private:
      blah blah
  
  
  public:
      blah blah
  
  virtual bool OnEvent (const SEvent&amp; event){
      if(left click)
         Obstacle obs(scn,randX,randY,randR);
  }
  
  }
  </code></pre>
  
  <p>Obstacle.h:</p>
  
  <pre><code>class Obstacle
  {
  private:
  
      static std::vector&lt;Obstacle&gt; *obs;
  
  public:
  
      Obstacle(scene::ISceneManager*, float, float, float);
      ~Obstacle();
  };
  </code></pre>
  
  <p>Obstacle cpp:</p>
  
  <pre><code>std::vector&lt;Obstacle&gt; *Obstacle::obs;
  
  Obstacle::Obstacle(scene::ISceneManager* scn, float x, float y, float radius)
  {
      //get and set the passed in params blah blah
  
      obs-&gt;push_back(this);
  
  
  }
  </code></pre>
  
  <p>This doesn't work, but hopefully you can see what I'm trying to achieve. Later on I want a function that will return a reference to obs so other classes can call this function and gain access to the vector to manipulate and read it.</p>