class Selectable
{
bool IsSelected() const;
};
class Unit : public Selectable
{
};
typedef std::list<Unit *UnitList;
UnitList * units = mapSurface->GetUnits();
UnitList::iterator selectedUnit = find_if(units->begin(), units-
>end(), mem_fun(&Unit::IsSelected));When no units are selected, find_if is still returning the first (and
only, in my test case) unit. I am even stepping through the calls to
mem_fun and IsSelected and it is returning false! What's even
stranger, the following code did the right thing:
UnitList::iterator selectedUnit = units->begin();
while(selectedUnit!=units->end())
{
if ((*selectedUnit)->IsSelected())
{
break;
}
++selectedUnit;
}
What am I doing wrong?!?
Thanks in advance!