This is what I tried, but I see that overloading only increments the variable if I assign it to another variable. I.e, The value of the variable on which I do the increment does not increase. So, in the example below variable newDay
is THU but currentDay
remains WED.
How do I define the overload operator to increment variable I am doing the operation on?
typedef enum days {MON, TUE, WED, THU, FRI, SAT, SUN} days;
inline days operator++ (days& d) {
return static_cast<days>((static_cast<int>(d) + 1) % 7);
}
int main(int argc, const char * argv[]) {
days currentDay = WED;
days newDay = ++currentDay;
cout << "Current day: " << currentDay << ", Stored day: " << calendar[0] << ", New day: " << newDay << endl;
}