fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. enum Month {
  6. january = 1,
  7. february,
  8. march,
  9. april,
  10. may,
  11. june,
  12. july,
  13. august,
  14. september,
  15. october,
  16. november,
  17. december
  18. };
  19.  
  20. class Date {
  21. int y, d;
  22. Month m;
  23.  
  24. public:
  25. Date(int yy, Month mm, int dd) // constructor
  26. : y(yy), d(dd), m(mm) { // member initializer
  27. }
  28.  
  29. Month& operator++(Month &m) {
  30. m = static_cast<Month>(m + 1);
  31. return m;
  32. }
  33.  
  34. void add_month() {
  35. ++m;
  36. }
  37. };
  38.  
  39. int main()
  40. {
  41. Month m = january;
  42. ++m;
  43. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:29:35: error: postfix ‘Month& Date::operator++(Month&)’ must take ‘int’ as its argument
         Month& operator++(Month &m) {
                                   ^
prog.cpp: In member function ‘void Date::add_month()’:
prog.cpp:35:13: error: no match for ‘operator++’ (operand type is ‘Month’)
             ++m;
             ^~~
prog.cpp: In function ‘int main()’:
prog.cpp:42:4: error: no match for ‘operator++’ (operand type is ‘Month’)
    ++m;
    ^~~
stdout
Standard output is empty