Member Nonmember Operators


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:

image from book

 ReturnDataType operator overloadedOperator (signature); 

image from book

or

image from book

 ReturnDataType operator className::overloadedOperator(signature); 

image from book

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).




Intermediate Business Programming with C++
Intermediate Business Programming with C++
ISBN: 738453099
EAN: N/A
Year: 2007
Pages: 142

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net