## Overloading Unary Operators
Unary operators take only one argument, like `++` or `!`
* For the `Time` class, `!` doesn't make sense, but `++` does
* Side note: `++` can be either **prefix** or **postfix**:
```cpp
int i = 0;
++i; // prefix
i++; // postfix
```
* `i++ * 2` is the same as `i * 2; i = i + 1;`
* `++i * 2` is the same as `i = i + 1; i * 2;`
* The prefix form is a bit easier to implement, so we'll do that
<footer>The <a href="https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#p9-dont-waste-time-or-space">C++ Core Guidelines</a> recommend preferring the prefix form for user-defined types</footer>
## Overloading `++`
* You might think that it should be defined as:
```cpp
void operator ++ ();
```
* But that's not quite right - it should return a `Time` reference:
```cpp
Time &operator ++ ();
```
* Otherwise you'd end up with an error if you tried to do `++i * 2`
* The implementation is straightforward thanks to our `increment` method:
```cpp
Time &Time::operator ++ () {
increment();
return *this; // dereference the pointer to itself
}
```
## Overloading Unary Operators
Unary operators take only one argument, like `++` or `!`
* For the `Time` class, `!` doesn't make sense, but `++` does
* Side note: `++` can be either **prefix** or **postfix**:
```cpp
int i = 0;
++i; // prefix
i++; // postfix
```
* `i++ * 2` is the same as `i * 2; i = i + 1;`
* `++i * 2` is the same as `i = i + 1; i * 2;`
* The prefix form is a bit easier to implement, so we'll do that
<footer>The <a href="https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#p9-dont-waste-time-or-space">C++ Core Guidelines</a> recommend preferring the prefix form for user-defined types</footer>
## Overloading `++`
* You might think that it should be defined as:
```cpp
void operator ++ ();
```
* But that's not quite right - it should return a `Time` reference:
```cpp
Time &operator ++ ();
```
* Otherwise you'd end up with an error if you tried to do `++i * 2`
* The implementation is straightforward thanks to our `increment` method:
```cpp
Time &Time::operator ++ () {
increment();
return *this; // dereference the pointer to itself
}
```
## Overloading stream operators: V1
* One way of solving this is to keep the public `write` method and call it from the non-member operator overload function:
```cpp
std::ostream &operator<<(std::ostream &out, const Time &t) {
t.write(out);
return out;
}
```
* We also need to return the stream reference in order to chain `<<` calls
* This declaration and implementation are placed **outside** the `Time` class
* There is another option if you don't want a public `write` method...