So here’s a snippet of my 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;
}
}
I’m getting the following error when compiling:
RoutingProtocolImpl.cc:368: error: argument of type bool (RoutingProtocolImpl::)(RoutingProtocolImpl::dv_entry*)' does not matchbool (RoutingProtocolImpl::)(RoutingProtocolImpl::dv_entry)'
The problem is that this:
bool RoutingProtocolImpl::hasInfCost(...)is a nonstatic member function.It requires an instance of the class to invoke on, ala:
obj->hasInfCost(...). However,remove_ifcares not and tries to call it ashasInfCost(...). These are incompatible.What you can do is make it
static:static bool RoutingProtocolImpl::hasInfCost(RoutingProtocolImpl::dv_entry *entry)This no longer requires an instance of the class to invoke. (It has no member variables, nothispointer, etc.). It can be treated as a “normal” function.