On Jan 11, 2014, at 11:01 AM, Nat Goodspeed
On Fri, Jan 10, 2014 at 2:19 AM, Oliver Kowalke
wrote: 2014/1/9 Vicente J. Botet Escriba
you can compare X and Y
You are surely right, but I don't see how? Could you show it?
implicit conversion to bool through operator bool()
Vicente, the bad case is when class X and class Y provide operator bool. A coder inadvertently writes:
if (myXinstance == myYinstance) ...
(only of course with names in the problem domain rather than names that emphasize their respective classes). This should produce a compile error; you don't want X and Y to be comparable; the comparison is meaningless. Yet the compiler accepts it, converting each of myXinstance and myYinstance to bool and then comparing those bool values. The code runs. The product ships. Then some customer gets badly whacked...
That isn't an issue when the conversion operator is explicit, which Vicente suggested.