title: Deleting a reference to a variable without affecting the original
body: <p>I have a struct which contains a reference to a vector.</p>
  
  <p>I then create a vector of this struct.</p>
  
  <p>I create three three instances of this struct in this vector.</p>
  
  <p>I then erase the second instance of the struct in the vector.</p>
  
  <p>This apparently causes the contents of testData2 to become the same as the contents of testData3!?</p>
  
  <p>How do I stop this from happening?  Is there something I should put in the destructor of the struct to stop this from happening?</p>
  
  <p>Or is what I am doing here terribly bad and if so, why?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;string&gt;
  #include &lt;cstdlib&gt;
  
  struct TESTSTRUCT
  {
      int &amp;testInt;
      std::vector&lt;int&gt; &amp;testVector;
  
      TESTSTRUCT(int &amp;testIntInput, std::vector&lt;int&gt; &amp;testVectorInput)
          :testInt(testIntInput), testVector(testVectorInput) {}
  
      TESTSTRUCT(const TESTSTRUCT &amp;source)
          :testInt(source.testInt), testVector(source.testVector) {}
  
      TESTSTRUCT &amp;operator=(const TESTSTRUCT &amp;source)
      {
          testInt = source.testInt;
          testVector = source.testVector;
  
          return *this;
      }
      virtual ~TESTSTRUCT(){}
  };
  
  int main()
  {
      std::vector&lt;int&gt; testData1;
      std::vector&lt;int&gt; testData2;
      std::vector&lt;int&gt; testData3;
      int a = 1;
      int b = 2;
      int c = 3;
  
      testData1.push_back(10);
      testData1.push_back(20);
      testData1.push_back(30);
  
      testData2.push_back(40);
      testData2.push_back(50);
      testData2.push_back(60);
  
      testData3.push_back(70);
      testData3.push_back(80);
      testData3.push_back(90);
  
      std::vector&lt;TESTSTRUCT&gt; *structVector = new std::vector&lt;TESTSTRUCT&gt;();
      structVector-&gt;push_back(TESTSTRUCT(a, testData1));
      structVector-&gt;push_back(TESTSTRUCT(b, testData2));
      structVector-&gt;push_back(TESTSTRUCT(c, testData3));
  
      std::cout&lt;&lt;&amp;testData1[0]&lt;&lt;std::endl;
      std::cout&lt;&lt;&amp;testData2[0]&lt;&lt;std::endl;
      std::cout&lt;&lt;&amp;testData3[0]&lt;&lt;std::endl;
  
      std::cout&lt;&lt;testData1[0]&lt;&lt;std::endl;
      std::cout&lt;&lt;testData2[0]&lt;&lt;std::endl;
      std::cout&lt;&lt;testData3[0]&lt;&lt;std::endl;
      structVector-&gt;erase(structVector-&gt;begin()+1);
      std::cout&lt;&lt;testData1[0]&lt;&lt;std::endl;
      std::cout&lt;&lt;testData2[0]&lt;&lt;std::endl;
      std::cout&lt;&lt;testData3[0]&lt;&lt;std::endl;
  
      std::cout&lt;&lt;&amp;testData1[0]&lt;&lt;std::endl;
      std::cout&lt;&lt;&amp;testData2[0]&lt;&lt;std::endl;
      std::cout&lt;&lt;&amp;testData3[0]&lt;&lt;std::endl;
  
      return 0;
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>00711220
  00711258
  00717C68
  10
  40
  70
  10
  70
  70
  00711220
  00711258
  00717C68
  Press any key to continue . . .
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>This here is an example from a larger program. The instances of the struct are for things I want a renderer to draw, and those things can change their position (and hence where the renderer should draw them).</p>