Binary Overloaded Operators as Member Functions

Consider using < to compare two objects of a String class that you define. When overloading binary operator < as a non-static member function of a String class, if y and z are String-class objects, then y < z is treated as if y.operator<(z) had been written, invoking the operator< member function with one argument declared below:

class String
{
public:
   bool operator<( const String & ) const;
   ...
}; // end class String

Overloaded operator functions for binary operators can be member functions only when the left operand is an object of the class in which the function is a member.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.243.100