Afficher un message
Vieux 15/01/2008, 04h30   #1
jonnyothan@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut find_if and mem_fun not getting expected results

The following code isn't producing expected results:

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!
  Réponse avec citation
 
Page generated in 0,04795 seconds with 9 queries