title: C++ invalid pointer error
body: <p>I'm getting invalid point error from the code below I don't see why. All I'm trying to do is to delete free some strings on the heap from a vector:</p>
  
  <pre><code>void func() {
      vector&lt;string&gt;* vec = new vector&lt;string&gt;;
      vec-&gt;push_back(*(new string("1")));
      vec-&gt;push_back(*(new string("2")));
  
      for(vector&lt;string&gt;::iterator itr = vec-&gt;begin(); itr != vec-&gt;end(); ++itr)
      {
          string* ptr = &amp;(*itr);
          delete(ptr);
      }
  }
  </code></pre>
  
  <p><strong>EDIT</strong>: is it because push_back creates a copy of the string?</p>