-1

Say i have a custom datatype:

MyBYTE

and I want to overload the == operator so that it can be compared to a BYTE like so:

if(b == mb)
{
    //can't overload that operator
}

or

if(mb == b)
{
    //CAN overload that operator
}

as far as I'm aware when mb is on the right, I cannot overload an operator within the MYBYTE class. Is this true? If so are there any workarounds?

Austin A
  • 566
  • 2
  • 15

1 Answers1

1

Operators can be declared as free functions. Almost all binary operators (except += and similar and ->* and similar) can be overloaded this way.

bool operator==(const MyBYTE& lhs, const BYTE& rhs) {
    // do stuff here
}

bool operator==(const BYTE& lhs, const MyBYTE& rhs) {
    // do stuff here
}
Ivan Smirnov
  • 4,365
  • 19
  • 30