PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > find_if and mem_fun not getting expected results
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
find_if and mem_fun not getting expected results

Réponse
 
LinkBack Outils de la discussion
Vieux 15/01/2008, 03h30   #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
Vieux 15/01/2008, 05h36   #2
jonnyothan@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: find_if and mem_fun not getting expected results

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).
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 12h50.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08394 seconds with 10 queries