... Does C++ not allow me to increment an enum using ++? :psyduck:

And I can't do ((int)the_enum)++, either

That's stupid. C never gave me these kinds of problems. Enums are fancy numbers. Let me use them as numbers.

Everything inside the computer is a fancy number

And it doesn't accept the_enum = 1 + (int)the_enum, either? :psyduck:

Are you TRYING to make me write this code in an uglier way where the_enum is an integer instead of an enum?!

If any C++ knowers know a workaround for this, please let me know

Well, I passed the compiler -fpermissive and now it works (but still prints a warning), but that's not great, especially since ++ still doesn't work

How do I make enums behave exactly like in C?!

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++

@vaporeon_ I gotta be real with you vappy, I have no idea what is going on here with the enum lol

Follow

@wallhackio @vaporeon_

enum gorp { FOO, BAR, BAZ };

is a type with inhabitants FOO, BAR, and BAZ, which are all (not so )secretly actually just integral values

@aescling @vaporeon_ I know enum basics but I don't understand the gorp = after the enum declaration

@wallhackio @aescling I declare a variable gorp of type enum gorp { FOO, BAR, BAZ }, and then assign it the value FOO

Sign in to participate in the conversation
📟🐱 GlitchCat

A small, community‐oriented Mastodon‐compatible Fediverse (GlitchSoc) instance managed as a joint venture between the cat and KIBI families.