title: Removing elements from C++ std::vector
body: <p>What is the proper way to remove elements from a C++ vector while iterating through it? I am iterating over an array and want to remove some elements that match a certain condition. I've been told that it's a bad thing to modify it during traversal.</p>
  
  <p>I guess I should also mention that this is an array of pointers that I need to free before removing them.</p>
  
  <p>EDIT:</p>
  
  <p>So here's a snippet of my code.</p>
  
  <pre><code>
  void RoutingProtocolImpl::removeAllInfinity()
  {
    dv.erase(std::remove_if(dv.begin(), dv.end(), hasInfCost), dv.end()); 
  }
  
  bool RoutingProtocolImpl::hasInfCost(RoutingProtocolImpl::dv_entry *entry)
  {
    if (entry->link_cost == INFINITY_COST)
    {
      free(entry);
      return true;
    }
    else
    {
      return false;
    }
  }
  
  </code></pre>
  
  <p>I'm getting the following error when compiling:
  <pre><code>
  RoutingProtocolImpl.cc:368: error: argument of type <code>bool (RoutingProtocolImpl::)(RoutingProtocolImpl::dv_entry*)' does not match</code>bool (RoutingProtocolImpl::<em>)(RoutingProtocolImpl::dv_entry</em>)'
  </pre></code></p>
  
  <p>Sorry, I'm kind of a C++ newb.</p>