If you take a look at the code below you can see I overloaded |= to allow ORing with ints. However I can't figure out how to overload =. Clang seems to say I need = to be in the enum body AND that the enum body can't have overloads. So I'm confused and it seems impossible?
I mostly want 0 to be an acceptable value of Test I don't actually need all ints to be casted but it's fine if they are (and maybe I will later)
I'm using C++ 20
#include <cstdio>
enum Test {
Test_NA,
one, two, three
};
inline Test& operator |= (Test&a, int b) { return a =(Test)(a|b); }
int mytest(Test v) {
return v == Test_NA ? 11 : v == three ? 33 : v;
}
int main() {
Test val = two;
printf("%d\n", mytest(val));
val|=1;
printf("%d\n", mytest(val));
printf("%d\n", mytest(one));
printf("%d\n", mytest(0)); //Error here
}