3 ms·
> I want to be able to define `plus` on my datatypes and I want to be able to define `+` on my datatypes. The problem with this approach is that, just as defin
by pansa2 6y ago
> I want to be able to define `plus` on my datatypes and I want to be able to define `+` on my datatypes.
The problem with this approach is that, just as defining `plus(int)` on a class `C` allows you to call `c.plus(1)`, defining `+(int)` allows `c + 1` but not `1 + c`.
Whereas the approach of adding overloads to a global `+` operator can support both `c + 1` and `1 + c`, by allowing you to define `+(C, int)` and `+(int, C)`.