title: Deleting a pointer from a vector using loops (not iterators)
body: <p>I have a method that is passed an object, finds that object in a vector of pointers by matching its address in a loop, and needs to remove the matching item from the vector without deleting the item (i.e the item needs to still exist in memory). Currently, this is the method:</p>
  
  <pre><code>void remove(Soldier&amp; soldier) {
      for (size_t i = 0; i &lt; armySize(); ++i) {
          if (army[i] == &amp;soldier) {
              cout &lt;&lt; army[i]-&gt;getName() &lt;&lt; "is removed" &lt;&lt; endl;
              army.erase(i);
              break;
          }
      }
  }
  </code></pre>
  
  <p>Where <code>soldier</code> is the object that needs to be removed and <code>army</code> is a vector of <code>Soldier</code> pointers. The <code>if</code> statement works, meaning that the address of <code>soldier</code> and an item in the vector matches. The problem is that I get an error that says "no matching member function for call to 'erase'". How would I fix this without using iterators (no new, delete or begin method)?</p>