自增 自检的运算符重载

Increment

Two operators: prefix increment & postfix increment

  1. // prefix increment
  2. MyTime& operator++()
  3. {
  4. this->minutes++;
  5. this->hours += this->minutes / 60;
  6. this->minutes = this->minutes % 60;
  7. return *this;
  8. }
  9. // postfix increment
  10. MyTime operator++(int)
  11. {
  12. MyTime old = *this; // keep the old value
  13. operator++(); // prefix increment
  14. return old;
  15. }

C++中可以重载的运算符image.png