Why if (var) … uses number conversion instead of boolean ?
I have a class that implements both :
operator int() { ....}
operator bool() { ....}
but if I use :
if (my_class_var) ....;
then the int conversion is used instead of boolean ?!!?!
EDIT:
As versedmarald say it is correct. I found what was the differnce.. I’m in fact using :
operator int() { ....}
operator bool() const { ... }
Still mesmerized, why the difference ?
gcc version 4.6.2
It doesn’t (using
g++at least). My guess would be there is an error in your conversion operators.Outputs: