title: error after calling simple getter method: basic_string::_S_create
body: <p>I have a simple function that prints out the name of a person using a getter method. It prints out the name fine the first time but the second time it throws an error and stops working.</p>
  
  <p>The debugger shows that the value of the persons name changes from what it was supposed to be to a jumble of random letters and numbers after the initial call is made.</p>
  
  <p>Any help would be much appreciated.</p>
  
  <p><code>error basic_string::_S_create</code></p>
  
  <pre><code>string personName("Jim");
  
  // check if person already exists (will return NULL in
  // the case of Jim during this test)
  Person *person = personList.getPerson(personName);
  
  if(!person)
  {
      cout &lt;&lt; "creating new person" &lt;&lt; endl;
      person = createPerson(personName);
      cout &lt;&lt; person-&gt;getName() &lt;&lt; endl; // prints 'Jim'
      cout &lt;&lt; person-&gt;getName() &lt;&lt; endl; // stops working here.
  }
  
  Person* createPerson(string name)
  {
      Person person(name);
      personList.addPerson(person);
      Person *foundPerson = personList.getPerson(name);
      return foundPerson;
  }
  </code></pre>
  
  <p>PersonList</p>
  
  <pre><code>...
  
  void PersonList::addPerson(Person&amp; person)
  {
      Person *person_ptr = &amp;person;
      personList.push_back(person_ptr);
  }
  
  Person* PersonList::getPerson(string name)
  {
      for(vector&lt;Person*&gt;::iterator it = personList.begin(); it != personList.end(); ++it)
      {
          if((*it)-&gt;getName() == name)
          {
              return *it;
          }
      }
  }
  
  ...
  </code></pre>
  
  <p>Person</p>
  
  <pre><code>class Person
  {
  public: 
      Person(string _name)
      string getName() const;
      ...
  private:
      string name;
      ...
  }
  
  ...
  
  Person::Person(string _name)
  :name(_name)
  {
  }
  
  string Person::getName() const
  {
      return name;
  }
  
  ...
  </code></pre>