PROPOSAL: Operator overloading by static member function
Janice Caron
caron800 at googlemail.com
Sun Oct 14 00:54:38 PDT 2007
On 10/13/07, oldrev <oldrev at gmail.com> wrote:
> It's a simple way to avoid using the ugly "opAdd_r", eg:
>
> struct Currency
> {
> private int m_value;
>
> public static Currency opAdd(Currency lhs, Currency rhs) {
> return Currency(lhs.m_value + rhs.m_value);
> }
> }
>
Returning to the original thread topic, how should the compiler react
if I "cheat" and do
struct Currency
{
private int m_value;
public static Currency opAdd(int lhs, int rhs) {
return Currency(lhs + rhs);
}
}
I'm sure you can see the problem here. I've just redefined int + int.
Surely, that can't be allowed?
More information about the Digitalmars-d
mailing list