PROPOSAL: Operator overloading by static member function

oldrev oldrev at gmail.com
Sat Oct 13 19:05:35 PDT 2007


Daniel Keep Wrote:

> 
> 
> oldrev 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);
> >   }
> > }
> 
> And how are you going to overload static opAdd_r, then?
> 
> I really don't see any need for this; opAdd_r is perfectly fine.
> 
> 	-- Daniel

We do not need opAdd_r anymore, it will be overloaded by static opAdd.

static A opAdd(A a, int i);
static A opAdd(int i, A a);

a+100 // it equals to opAdd(a, 100);
100+a //opAdd(100, a)

Regards,
- oldrev



More information about the Digitalmars-d mailing list