title: Alternatives to std::vector due to reallocation that invalidates pointers to elements
body: <p>this might be a newb question (i am) but i've searched as much as i could to find a solution to the following problem </p>
  
  <p>I have the following scenario (heavily distilled of course):</p>
  
  <pre><code>class Container
  {
  std::vector&lt;Object&gt; obj;
  };
  
  class Pointers
  {
  std::vector&lt;Object*&gt; obj_ptr;
  };
  </code></pre>
  
  <p>I have a routine that pushes back an element of type Object to the vector <strong>obj</strong> in Container then pushes back the pointer to that same element to <strong>obj_ptr</strong>.</p>
  
  <p>the overall idea is that <strong>obj_ptr[i]</strong> == <strong>&amp;obj[i]</strong> throughout the life of the program. </p>
  
  <p>The problem I run into is that whenever the capacity of <strong>obj</strong> needs to increase all the pointers are invalidated, making the <strong>obj_ptr</strong> completely useless. I have tried both obj.reserve() using the maximum expected size (around 10^7) and initializing the vector with that same size. Problem still persists. </p>
  
  <p>Not sure if it's important, but I'm using VS 2015 Com.</p>
  
  <p>Thanks!</p>