title: C++ vector iterator: erase() last item crash
body: <p>The following code checks if a ball overlaps with a brick. The brick is highlighted and erased from the list if the overlap occurs.</p>
  
  <p>I am experiencing a core dump when erasing only the last item in the vector <i>brickWall</i>.
  Commenting the <i>erase()</i> line, the code seems to work well.<br>
  After looking through similar issues on forums, I believed I was iterating through and erasing the items in the vector properly, but I suspect it may not be the case.<p>
  Any suggestions on this code would be much appreciated!</p>
  
  <pre><code>void Game::updateEntities()
  {
      ballMother.update();
      for (std::vector&lt;gdf::Entity&gt;::iterator it = brickWall.begin(); it != brickWall.end(); ++it) 
      {
          if (it-&gt;getRect().intersects(ballMother.getRect())) {
              it-&gt;rect.setFillColor(sf::Color::Red);
              it = brickWall.erase(it);
          }
          else {
              it-&gt;rect.setFillColor(it-&gt;colour);                
          }
      }
  }
  </code></pre>