user defined implicit casts

Jarrett Billingsley kb3ctd2 at yahoo.com
Tue Jul 31 14:22:46 PDT 2007


"Reiner Pope" <some at address.com> wrote in message 
news:f8m84m$30eq$1 at digitalmars.com...
> I can think of one example where global operator overloads make sense:
>
> // stores a list of T, with opIndex, opCat, etc
> class List(T) { ... }
>
> In this case it might be reasonable to define a function which does a 
> elementwise add of two List!(int)s to produce a third:
>
> List!(int) opAdd(List!(int) a, List!(int) b) { ... }
>
> But this operator clearly doesn't belong in the List class, as in the 
> general case, you can't add two lists together.

Can you generalize that to a List!(any integer type)?  What if (I know the 
chances are slim but bear with me) you created a class derived from List 
which wanted to change the behavior of opAdd?  And is there anything that 
you absolutely cannot do with member operator overloads, or problems which 
static/global operator overloads solve more elegantly than member operator 
overloads? 





More information about the Digitalmars-d mailing list