title: How to erase & delete pointers to objects stored in a vector?
body: <p>I have a vector that stores pointers to many objects instantiated dynamically, and I'm trying to iterate through the vector and remove certain elements (remove from vector and destroy object), but I'm having trouble. Here's what it looks like:</p>
  
  <pre><code>    vector&lt;Entity*&gt; Entities;
      /* Fill vector here */
      vector&lt;Entity*&gt;::iterator it;
      for(it=Entities.begin(); it!=Entities.end(); it++)
          if((*it)-&gt;getXPos() &gt; 1.5f)
              Entities.erase(it);
  </code></pre>
  
  <p>When any of the Entity objects get to xPos>1.5, the program crashes with an assertion error...
  Anyone know what I'm doing wrong?</p>
  
  <p>I'm using VC++ 2008.</p>