#include #include #include using milliDag = unsigned int; class Time { public: Time(milliDag milliDags) : milliDags{milliDags} {} Time() : milliDags{0} {} Time& operator++() { if ( milliDags == 999) { milliDags = 0; } else { ++milliDags; } return *this; } Time operator++(int) { Time old{*this}; ++*this; return old; } Time operator+(uint rhs) const { Time newtime{milliDags + rhs}; if (newtime.milliDags > 999) { newtime.milliDags = newtime.milliDags % 1000; } return newtime; } std::string to_string() const { std::stringstream sstream{}; sstream << milliDags; return sstream.str(); } private: milliDag milliDags; }; std::ostream& operator<<(std::ostream& os, Time const& rhs) { os << rhs.to_string(); return os; } Time operator+(uint lhs, Time const& rhs) { return rhs + lhs; } int main() { std::cout << "Testing increment" << std::endl; Time time1{}; ++(++time1); std::cout << time1++ << std::endl; std::cout << time1 << std::endl; Time time2{999}; std::cout << time2++ << std::endl; std::cout << time2 << std::endl; std::cout << "\nTesting binary addition operators:" << std::endl; Time const time3{}; std::cout << time3 + 999 << std::endl; std::cout << time3 + 1000 << std::endl; std::cout << time3 + 3500 << std::endl; Time const time4{}; std::cout << 999 + time4 << std::endl; std::cout << 1000 + time4 << std::endl; std::cout << 3500 + time4 << std::endl; }