I have a type called MyType that is an int:
typedef int MyType;
It gets treated as an int throughout the code.
I’d like to be able to overload an operator separately for both int and MyType:
class C
{
public:
C& operator>>(int i) {}
C& operator>>(MyType i) {}
};
but I can’t:
overload.cpp:7:7: error: 'C& C::operator>>(MyType)' cannot be overloaded
overload.cpp:6:7: error: with 'C& C::operator>>(int)'
Can I have my cake and eat it too?
As per usual, you need a strong typedef. One implementation of that is
BOOST_STRONG_TYPEDEF.