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_ @wallhackio vaporeon loves implicit casts
@aescling @wallhackio "Implicit casts" meaning that when I do e.g. int *ptr = malloc(whatever) and malloc returns a void*, then it gets automatically casted to int*? And that an enum gets casted to an integer because it is an integer? Yes, I do like that
@vaporeon_ @wallhackio imo “enums are exactly the same as ints” is exactly the opposite of the point of having an enumerated type
@vaporeon_ @wallhackio i’m curious now, when you were learning haskell, did type definitions like
data Whatever = Thing1 | Thing2
ever bother you in the way that the value of Thing1 is kind of abstract? i remember (the equivalent to )this taking a while fur me to get used to when i was furst learning OCaml