PART I
C h a p t e r 9 :
O p e r a t o r O v e r l o a d i n g
231
PART IPART I
The output from the program is shown here:
Here is a: 5, 6, 7
Here is b: 10, 10, 10
Here is c: 0, 0, 0
c is false.
a & b is true.
a & c is false.
a | b is true.
a | c is true.
In this approach, the
&
,
|
, and
!
operator methods each return a
bool
result. This is necessary
if the operators are to be used in their normal manner (that is, in places that expect a
bool
result). Recall that for all built-in types, the outcome of a logical operation is a value of type
bool
. Thus, having the overloaded versions of these operators return type
bool
is a rational
approach. Unfortunately, this approach works only if you will not be needing the short-
circuit operators.
Do'stlaringiz bilan baham: |