Static operator overloads are possible why?

Sean Kelly sean at f4.ca
Sat Jun 30 08:56:16 PDT 2007


Giles Bathgate wrote:
> Thanks sean you have answered the question in the subject line, I posed the question that way to prevoke a response. I agree that static operator overloads should be possible, my post is really directed at the issue of how one would use them.
> 
> e.g in my example for static operator overloads if t += b; translates to Test.opAddAssign(b); then where does the reference to t go? surely it should be Test.opAddAssign(t,b);

There is no reference to t in that case -- it's a static operation.  ie. 
you can do things like this:

     struct S {
         static int opMul( int x ) { return x * 5; }
     }

     int y = S * 2; // should equal 10

This becomes useful mostly when you have multiple operator overloads for 
different types, and do different things for each type.


Sean



More information about the Digitalmars-d mailing list