Feature: Access to lvalue in static operator overloads

Manfred Nowak svv1999 at hotmail.com
Mon Jul 9 03:14:09 PDT 2007


GilesBathgate wrote

> In a previous post I was complaining that I could not access the
> lvalue in a static operator overload. 

In D the lvalue of a static operator overload of a class are all 
those entities of the class that are declared static; one can access 
them from within the body of the static operator and use that 
operator in the usual way:

import std.stdio;
class Test
{
    static char[] Name= "foo";;

    static void opAddAssign( Test)
    {
        writefln("%s", Name);
    }
}

void main()
{
    Test T;
    Test B;
    T += B; // compiles!
}

So the issues of your proposal seem to be:
1) Why do one need to initialize instances of classes explicitely?
2) Get rid of the differences between static and non-static!

Both would severely disturb some main paradigms of D.
-manfred



More information about the Digitalmars-d mailing list