November 2001
Beginner
1128 pages
29h 12m
English
For many operators, you have a choice between using member functions or nonmember functions to implement operator overloading. Typically, the nonmember version would be a friend function so that it can access directly the private data for a class. For example, consider the addition operator for the Time class. It had this prototype in the Time class declaration:
Time operator+(const Time & t) const; // member version
Instead, the class could have used the following prototype:
friend Time operator+(const Time & t1, const Time & t2); // non-member version
The addition operator requires two operands. For the member function version, one is passed implicitly via the this pointer and the ...
Read now
Unlock full access