Hello @wallhackio the C++ knower, I need C++ help. Is there any way to make enums behave exactly like in C, or at least not complain about increment? Here's a minimum example of what's NOT working:
int main() {
enum gorp { FOO, BAR, BAZ } gorp = FOO;
gorp++;
}
The compiler rejects it:
$ LC_ALL=C g++ -fpermissive test.cpp
test.cpp: In function 'int main()':
test.cpp:3:7: warning: no 'operator++(int)' declared for postfix '++', trying prefix operator instead [-fpermissive]
3 | gorp++;
| ~~~~^~
test.cpp:3:7: error: no match for 'operator++' (operand type is 'main()::gorp')
I can replace gorp++; with gorp=(int)gorp+1;, and then it'll compile iff I set the -fpermissive option, but I don't like that because it's uglier and less readable than gorp++
enum gorp { FOO, BAR, BAZ };
is a type with inhabitants FOO, BAR, and BAZ, which are all (not so )secretly actually just integral values
@wallhackio @aescling I declare a variable gorp of type enum gorp { FOO, BAR, BAZ }, and then assign it the value FOO
@aescling @vaporeon_ I know enum basics but I don't understand the gorp = after the enum declaration