previous | start | next

## Operator Overloading

- You can also overload the input operator to read in other types of objects.

  >     istream & operator>>(istream& in, Time& a)
  >     {
  >        int hours;
  >        int minutes;
  >        int seconds;
  >        in >> hours >> minutes >> seconds;
  >        a = Time(hours, minutes, seconds);
  >        return in;
  >     }

- Note that the `>>` operator returns the input stream just like the `<<` operator.
- Unlike the `<<` operator, the `>>` operator must have a parameter of `Time&`.
- It is easy to go overboard overloading operators! Using inappropriate operators can make programs more difficult to read.
  - Does it make sense to overload `*`, `/` or `%` for Time objects?

previous | start | next