title: C++ Deleting an object in a vector
body: <p>I am currently using a vector to hold the people in a program. I am trying to delete it with</p>
  
  <p><code>vectorname.erase(index);</code></p>
  
  <p>I pass the vector in a function, as well as the element that I want to delete. My main problem is how can I improve my code in terms of compilation speed?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  using namespace std;
  
  class person {
      private:
          string name;
      public:
          person() {}
          person(string n):name(n){}
          const string GetName() {return name;}
          void SetName(string a) { name = a; }
  };
  
  void DeleteFromVector(vector&lt;person&gt;&amp; listOfPeople,person target) {
      for (vector&lt;person&gt;::iterator it = listOfPeople.begin();it != listOfPeople.end();++it) {//Error 2-4
          if (it-&gt;GetName() == target.GetName()) {
              listOfPeople.erase(it);
              break;
          }
      }
  }
  
  int main(){
      //first group of people
      person player("Player"), assistant("Assistant"), janitor("Janitor"), old_professor("Old Professor");
  
      //init of vector
      vector&lt;person&gt; listOfPeople = { player, assistant, janitor, old_professor };
  
      DeleteFromVector(listOfPeople, janitor);
  }
  </code></pre>