title: c++ vector of class object pointers
body: <p>What I am trying to do is essentially create two vectors of objects, where some objects are entered into both lists and some are just entered into one. The first problem I found was that when I used push_back() to add an object into both lists the object was copied so that when I changed it from one list the object did not change in the other. To get around this I tried to create a list of pointers to objects as one of the lists. However when I accessed the pointer later on the data seemed to be corrupted, the data member values were all wrong. Here are some snippets of my code:</p>
  
  <p>Definition of vectors:</p>
  
  <pre><code>vector&lt;AbsorbMesh&gt; meshList;
  vector&lt;AbsorbMesh*&gt; absorbList;
  </code></pre>
  
  <p>...
  Adding an object to both:</p>
  
  <pre><code>AbsorbMesh nurbsMesh = nurbs.CreateMesh(uStride, vStride);
  
  // Add to the absorption list
  absorbList.push_back(&amp;nurbsMesh);
  // Store the mesh in the scene list
  meshList.push_back(nurbsMesh);
  </code></pre>
  
  <p>Accessing the object:</p>
  
  <pre><code>if (absorbList.size() &gt; 0)
  {
  float receivedPower = absorbList[0]-&gt;receivedPower;
  }
  </code></pre>
  
  <p>What am I doing wrong?</p>