Static operator overloads are possible why?
GilesBathgate
gilesbathgate at gmail.com
Thu Jul 5 12:24:34 PDT 2007
> Or in other words:
> for the entities of a class that are declared `static' the D-compiler
> automatically establishes a singleton and that singleton can be
> accessed
> 1) by the name of the class or
> 2) every instance of the class
Yeah I know, I am a programmer.
If you can translate this C# code into D I will give you a medal
public class Test
{
public string Name;
public static Test operator +(Test lvalue, Test rvalue)
{
if (lvalue == null) { lvalue = new Test(); lvalue.Name = "foo"; }
if (rvalue == null) { rvalue = new Test(); rvalue.Name = "bar"; }
Console.Write(lvalue.Name);
Console.Write(rvalue.Name);
return rvalue;
}
}
static void Main(string[] args)
{
Test T = null;
Test B = null;
T += B;
}
More information about the Digitalmars-d
mailing list