Intermediate Business Programming with C++
Member & Nonmember Operators
Operators on classes may be either member or nonmember operators. All that is required is that one of the operands must be a class object. The constructs of the prototypes are:
ReturnDataType operator overloadedOperator (signature);
or
ReturnDataType operator className::overloadedOperator(signature);
for non-member and member operator functions respectively.
The signature of a nonmember operator must have as the left operand a non-class object as an explicit operand while the member operator has an object of the class as an implicit left operand. For example if * ( ) is a non-member operator then a * b would have a as a non-object and b as an object. If *( ) is a member operator, then a * b would have a as an object of the class while b does not need to be an object. In the first case since *( ) would not be a member operator, then a * b really means *(a,b). In the second case since where *( ) is a member operator, then the statement a * b really means a.*(b).
Категории