C++ short-circuiting of booleans
问题 I'm new to c++ and am curious how the compiler handles lazy evaluation of booleans. For example, if(A == 1 || B == 2){...} If A does equal 1, is the B==2 part ever evaluated? 回答1: No, the B==2 part is not evaluated. This is called short-circuit evaluation. Edit: As Robert C. Cartaino rightly points out, if the logical operator is overloaded, short-circuit evaluation does not take place (that having been said, why someone would overload a logical operator is beyond me). 回答2: Unless the ||