previous | start | next

## Operator Overloading

- Many classes use operators such as `++`, `*` and `==.`
- Giving a new meaning to an operator is called operator overloading.
- You can overload an operator by defining a function whose name is operator followed by the operator symbol.
- For example, you can define the difference between two `Time` objects as the number of seconds between them.

  >     int operator-{Time a, Time b)
  >     {
  >        return a.seconds_from(b);
  >     }

- Now you can use the `-` operator instead of calling `seconds_from`.

  >     Time now;
  >     Time morning(9, 0, 0);
  >     long seconds_elapsed = now - morning;

previous | start | next