title: C++, Visual Studio 2015, Vector iterator not dereferencable
body: <p>Ok, so i managed to write a method for deleting missles in my game, but i am constantly getting this error and i don't know why. Any ideas how to deal with the problem? Besides, i'd like to get rid of this i iterator, but then i don't know how to use properly delete and erase for the missle.</p>
  
  <pre><code>    {
          int i = 0;
          for (auto it = missle_vector.begin(); it != missle_vector.end(); ++it) {
              score += missle_vector[i]-&gt;collision(i, missle_vector, enemy_vector, obstacle_vector, 1);
              displayMissle(**it);
              (*it)-&gt;moove(50, 0);
              i++;
          }
      } //this is how i use it
  
  int Missle::collision(unsigned int i, vector &lt;Missle*&gt; &amp;missle_vector, vector &lt;Enemy*&gt; &amp;enemy_vector,
                              vector &lt;Obstacle*&gt; &amp;obstacle_vector, bool G)
  {
  int hit=0;
  for (auto it=enemy_vector.begin(); it!=enemy_vector.end(); )
  {
      double x, y;
      x=(*it)-&gt;getX()-getX();
      y=(*it)-&gt;getY()-getY();
      if (x&lt;64 &amp;&amp; x&gt;-151 &amp;&amp; y&lt;14 &amp;&amp; y&gt;-103)
      {
          delete  missle_vector[i];
          missle_vector.erase(missle_vector.begin() + i);
          delete *it;
          enemy_vector.erase(it);
          hit++;
      }
      else
          ++it;
  }
  if(G){
  for (auto it=obstacle_vector.begin(); it!=obstacle_vector.end(); ++it)
      {
          double x, y;
          x=(*it)-&gt;getX()-getX();
          y=(*it)-&gt;getY()-getY();
          if (x&lt;64 &amp;&amp; x&gt;-61 &amp;&amp; y&lt;14 &amp;&amp; y&gt;-61)
          {
              delete  missle_vector[i];
              missle_vector.erase(missle_vector.begin()+i);
          }
      }
  }
  if (getX()&gt;1920)
  {
      delete missle_vector[i];
      missle_vector.erase(missle_vector.begin()+i);
  }
  return hit;
  } //method itself
  </code></pre>