There's a lot of information, examples etc. for operator overloading of all kinds on the web. But I can't for the life of me find an example on how to do this for a simple enum and, say, the |=
or the +=
operators.
For a bitwise or
the implementation is this:
inline MyEnum operator | (MyEnum a, MyEnum b)
{
return (MyEnum)((int)a | (int)b);
}
All the examples I found for compound operations however are for classes; which can easily take the this
pointer for the LHS. In an enum I don't have that, so what's the correct syntax?
Update: I have already tried this version:
inline MyEnum operator |= (MyEnum a, MyEnum b)
{
return (MyEnum)((int)a | (int)b);
}
and it compiles, but doesn't return the correct bitwise or
value.