It's possible to convert enumeration value to int but no an implicit reverse conversion. That's why
currentMonth = currentMonth + 1 expression is wrong. More precisely, the right side is legal subexpression (treated as
(int)currentMonth + 1 and has int type) but no
implicit int to months conversion and the assignment is not legal here.
However it's possible to convert int value to enumerator
explicitly, for example:
months m = static_cast<months>(1); // = jan
It seems that
return static_cast<month>(currentMonth+1) solves the problem. No, it's wrong. If currenMonth == dec, we have 13 - no months type value of static_cast<months>(13).
Fortunately, it's so easy to correct an expression in return statement...
Do it yourself
Reputation Points: 1234
Solved Threads: 347
Postaholic
Offline 2,001 posts
since Jul 2008