I have a problem that when c++ evaluates the while statement, it also evaluates the underlying if statement even if the while statement condition is not met.
ite_candidats is a custom iterator on a binary map tree. When there is no more nodes to visit, ite_candidat evaluates to NULL. So the while ends. But, I get a assertion failure from ite_candidats.clecourante() call, saying my underlying node is NULL. It shouldn’t evaluate ite_candidats.clecourante() because it wasn’t meant to get to it.
I ran the program in debug mode, and !!ite_candidats really evaluates to false when there is no more nodes to visit. If I comment out the if block, the program gets out of the while loop and everything is ok…
The operator overloading of ite_candidats operator bool() doesn’t call clecourante().
while(!!ite_candidats){
if(ite_candidats.clecourante() != nompersonne){
{...}
}
ite_candidats++;
}
It is impossible. If it evaluates
ifthen it enters intowhile. No ahead computation isC++.P.S. Why do you have two negations in
while?