|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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! |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
Turns out it was a compiler error. I'm not great at x86, but the
IsSelected function was only setting the low byte of eax to 0. Then when it returned, eax was converted to 1 because the higher 3 bytes had a non-zero value. Changing IsSelected to return int fixed the problem. This was using MSVC 7.1, by the way (I know, it's ancient). |
|
![]() |
| Outils de la discussion | |
|
|