Enabling the Short-Circuit Operators
To enable the use of the
&&
and
||
short-circuit operators, you must follow four rules.
First, the class must overload
&
and
|
. Second, the return type of the overloaded
&
and
|
methods must be the same as the class for which the operators are being overloaded. Third,
each parameter must be a reference to an object of the class for which the operator is being
overloaded. Fourth, the
true
and
false
operators must be overloaded for the class. When
these conditions have been met, the short-circuit operators automatically become available
for use.
The following program shows how to properly implement the
&
and
Do'stlaringiz bilan baham: |