'"no 'operator++(int)' declared for postfix '++' [-fpermissive]" on enums [duplicate]
I have got the enum
enum ProgramID
{
A = 0,
B = 1,
C = 2,
MIN_PROGRAM_ID = A,
MAX_PROGRAM_ID = C,
} CurrentProgram;
Now, I am trying to increment CurrentProgram like this: CurrentProgram++, but the compiler complains: no 'operator++(int)' declared for postfix '++' [-fpermissive]. I think there IS such an operator that increments "enums", but if there is not, how do I get the successor of one of these values?
Solution 1:[1]
No, you are wrong, there is no such operator.
To get the next one, convert your value to an int, increment it, then reinterpret_cast it back to your enum. Note that going out of bounds can eventually lead to undefined behaviour, so checks are a good idea.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
