title: Pointer to STL container behaviour
body: <p>I have this class:</p>
  
  <pre><code>class Model3D
  {
  public:
      void AddVert( Vec3D vert ) { vertices.push_back( vert ); }
      void AddTri( Vec3D *v_0, Vec3D *v_1, Vec3D *v_2 );
      void Draw( HDC hdc );
  
      std::vector&lt;Vec3D&gt; vertices;
      std::vector&lt;Triangle3D&gt; polys;
  };
  </code></pre>
  
  <p>Also relevant, the Triangle3D type is defined as follows: (it is small because it's not finished)</p>
  
  <pre><code>class Triangle3D
  {
  public:
      Vec3D  *verts[3];
  
  };
  </code></pre>
  
  <p>Also, Here is AddTri()  </p>
  
  <pre><code>void Model3D::AddTri( Vec3D *v_0, Vec3D *v_1, Vec3D *v_2 )
  {
  Triangle3D triangle;
  triangle.verts[0] = v_0;
  triangle.verts[1] = v_1;
  triangle.verts[2] = v_2;
  
  polys.push_back( triangle );
  }
  </code></pre>
  
  <p><strong>Vertices</strong> members are given initial values. Looking at these members in debug through the pointers in <strong>Triangle3D</strong> shows these values correctly</p>
  
  <p>Finally, I attempt to alter the members of <strong>vertices</strong> here:</p>
  
  <pre><code>std::vector&lt;Vec3D&gt;::iterator j;
  
  for (j = vertices.begin(); j != vertices.end(); ++j)
      {
      j-&gt;x = ( j-&gt;x ) / ( j-&gt;z );
      j-&gt;y = ( j-&gt;y ) / ( j-&gt;z );
      }
  </code></pre>
  
  <p>After this loop completes, using the debugger, if I inspect the <strong>vertices</strong> vector, the members are modified as hoped. Yet, when I inspect the pointers to these members in the <strong>Triangle3D</strong> class, they are unchanged. Why is this?</p>
  
  <p><strong>EDIT</strong> here is a snippet of vertices and triangles being added (defines a cube):</p>
  
  <pre><code>Model3D Cube( Vec3D center, int size )
  {
  Vec3D vert;
  Model3D model;
  
  vert.z = .5;
  
  vert.x = center.x - (float)( 0.5f * size );
  vert.y = center.y + (float)( 0.5f * size );
  
  model.AddVert( vert );
  
  vert.x = center.x + (float)( 0.5f * size );
  vert.y = center.y + (float)( 0.5f * size );
  model.AddVert( vert );
  
  vert.x = center.x + (float)( 0.5f * size );
  vert.y = center.y - (float)( 0.5f * size );
  model.AddVert( vert );
  
  vert.x = center.x - (float)( 0.5f * size );
  vert.y = center.y - (float)( 0.5f * size );
  model.AddVert( vert );
  
  vert.z = 1;
  //center.x += 120;
  //center.y += 120;
  
  vert.x = center.x - (float)( 0.5f * size );
  vert.y = center.y + (float)( 0.5f * size );
  
  model.AddVert( vert );
  
  vert.x = center.x + (float)( 0.5f * size );
  vert.y = center.y + (float)( 0.5f * size );
  model.AddVert( vert );
  
  vert.x = center.x + (float)( 0.5f * size );
  vert.y = center.y - (float)( 0.5f * size );
  model.AddVert( vert );
  
  vert.x = center.x - (float)( 0.5f * size );
  vert.y = center.y - (float)( 0.5f * size );
  model.AddVert( vert );
  
  //front
  model.AddTri( &amp;model.vertices[0], &amp;model.vertices[1], &amp;model.vertices[2] );
  model.AddTri( &amp;model.vertices[2], &amp;model.vertices[3], &amp;model.vertices[0] );
  
  //top
  model.AddTri( &amp;model.vertices[4], &amp;model.vertices[5], &amp;model.vertices[1] );
  model.AddTri( &amp;model.vertices[1], &amp;model.vertices[0], &amp;model.vertices[4] );
  
  //bottom
  model.AddTri( &amp;model.vertices[3], &amp;model.vertices[2], &amp;model.vertices[6] );
  model.AddTri( &amp;model.vertices[6], &amp;model.vertices[7], &amp;model.vertices[3] );
  
  //left
  
  model.AddTri( &amp;model.vertices[4], &amp;model.vertices[0], &amp;model.vertices[3] );
  model.AddTri( &amp;model.vertices[3], &amp;model.vertices[7], &amp;model.vertices[4] );
  
  //right
  model.AddTri( &amp;model.vertices[1], &amp;model.vertices[5], &amp;model.vertices[6] );
  model.AddTri( &amp;model.vertices[6], &amp;model.vertices[2], &amp;model.vertices[1] );
  
  //back
  model.AddTri( &amp;model.vertices[5], &amp;model.vertices[4], &amp;model.vertices[7] );
  model.AddTri( &amp;model.vertices[7], &amp;model.vertices[6], &amp;model.vertices[5] );
  
  return model;
  }
  </code></pre>
  
  <p>And here is the Draw method:</p>
  
  <pre><code>void Model3D::Draw( HDC hdc )
  {
  std::vector&lt;Triangle3D&gt;::iterator i;
  std::vector&lt;Vec3D&gt;::iterator j;
  
  for (j = vertices.begin(); j != vertices.end(); ++j)
      {
      j-&gt;x = ( j-&gt;x ) / ( j-&gt;z );
      j-&gt;y = ( j-&gt;y ) / ( j-&gt;z );
      }
  
  for (i = polys.begin(); i != polys.end(); ++i)
      {
      DrawLine( hdc, *i-&gt;verts[0], *i-&gt;verts[1], WHITE );
      DrawLine( hdc, *i-&gt;verts[1], *i-&gt;verts[2], WHITE );
      DrawLine( hdc, *i-&gt;verts[2], *i-&gt;verts[0], WHITE );
      }
  }
  </code></pre>