I was bored and came up with such hack (pseudocode):
1 struct proxy {
2 operator int(); // int function
3 operator double(); // double function
4
In your example, you allow casts to int
and float
. As long as these two casts perform the same basic logic, i.e. operator int() { return operator float(); }
I see no problem. If they behave differently, this could definitely result in some surprises or ambiguities. This is because I would expect numeric results to have a coherent meaning.