Why I must overload operator false? #7671
-
Machine translation may cause difficulty in expression, and reading may require imagination. I flipped through the document and saw that 'false' works like this
So you can get "&&" This means that if I don't write & or if the return type is not my own, then false is of no use. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Primarily because if you do not overload this, you could end up with very strangely behaving types/values. This acts as a safeguard, forcing you to at least think about this so you don't accidentally get into a confusing situation. Given that it is generally trivial to overload the other at the same time, this protection is viewed as more useful than not. |
Beta Was this translation helpful? Give feedback.
-
Just like From the other hand to explain this, |
Beta Was this translation helpful? Give feedback.
If you overload operator
true
then usages in||
will properly short circuit. If you overload operatorfalse
then usages in&&
will properly short circuit. If you don't overload operatorfalse
then shortcircuiting will not work properly. That could lead to confusion where||
works as one expects, but&&
does not.