August 2012
Intermediate to advanced
976 pages
30h 17m
English
When we define an overloaded operator, we must decide whether to make the operator a class member or an ordinary nonmember function. In some cases, there is no choice—some operators are required to be members; in other cases, we may not be able to define the operator appropriately if it is a member.
The following guidelines can be of help in deciding whether to make an operator a member or an ordinary nonmember function:
• The assignment (=), subscript ([]), call (()), and member access arrow (->) operators must be defined as members.
• The compound-assignment operators ordinarily ought to be members. However, unlike assignment, they are not required to be members.
• Operators that change the state ...
Read now
Unlock full access