title: STL list iterator won't update my object
body: <p>I am using a list iterator to set all the ages of the Pets to 1 but the change won't persist outside the for loop:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;stdio.h&gt;
  #include &lt;list&gt;
  
  using namespace std;
  
  class Pet{
    public:
    int age;
  };
  
  class Person{
    public:
    list&lt;Pet&gt; pets;
  };
  
  
  int main(int argc, char **argv) {
    Person bob;
    Pet p1;
    p1.age = 0;
    bob.pets.push_back(p1);
  
    cout &lt;&lt; "Start with: "&lt;&lt;p1.age &lt;&lt; endl;
  
    std::list&lt;Pet&gt;::iterator itPet;
    for (itPet = bob.pets.begin(); itPet != bob.pets.end(); ++itPet) {
      Pet p = (*itPet);
      p.age = 1;
      cout &lt;&lt; "Right after setting to 1: "&lt;&lt;p.age &lt;&lt; endl;
    }
  
    cout &lt;&lt; "After the for loop: "&lt;&lt;p1.age &lt;&lt; endl;
    return 0;
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>Start with: 0
  Right after setting to 1: 1
  After the for loop: 0
  </code></pre>
  
  <p>Why is p1 not updated? And what has been updated if not p1?</p>
  
  <p>Thanks!</p>