title: c++ garbage values in vector of pointer
body: <p>When I do:</p>
  
  <pre><code>for(i=0; i&lt;size; i++){
      //create objectA here
      vectorA.push_back(objectA);
      pvectorA.push_back(&amp;vectorA[i]);
  }
  </code></pre>
  
  <p>some elements of pvectorA is garbage. However when I do:</p>
  
  <pre><code>for(i=0; i&lt;size; i++){
      //create objectA here
      vectorA.push_back(objectA);
  
  }
  for(i=0; i&lt;size; i++){
      pvectorA.push_back(&amp;vectorA[i]);
  }
  </code></pre>
  
  <p>Everything is okay. Why is it happens?</p>