fork download
  1. #include <iostream>
  2.  
  3. class Date {
  4. public:
  5. Date(int y, int m, int d)
  6. :y_ {y}, m_ {m}, d_ {d}
  7. {
  8. }
  9.  
  10. std::string to_s() {
  11. return std::to_string(y_) + '-' +
  12. std::to_string(m_) + '-' +
  13. std::to_string(d_);
  14. }
  15.  
  16. Date& operator+=(Date other) {
  17. y_ += other.y_;
  18. m_ += other.m_;
  19. d_ += other.d_;
  20.  
  21. return *this;
  22. }
  23.  
  24. private:
  25. int y_, m_, d_;
  26. };
  27.  
  28. Date Day(int d) {
  29. return Date(0, 0, d);
  30. }
  31.  
  32. int main() {
  33. Date d {2018, 01, 03};
  34. std::cout << d.to_s() << '\n';
  35. d += Day(1);
  36. std::cout << d.to_s() << '\n';
  37. return 0;
  38. }
Success #stdin #stdout 0s 4464KB
stdin
Standard input is empty
stdout
2018-1-3
2018-1-4