Static operator overloads are possible why?
Jarrett Billingsley
kb3ctd2 at yahoo.com
Sat Jun 30 09:29:03 PDT 2007
"Giles Bathgate" <gilesbathgate at gmail.com> wrote in message
news:f63vfc$29vg$1 at digitalmars.com...
> public class Test
> {
> public char[] Name;
>
> public Test opAddAssign(Test value)
> {
> writefln(value.Name);
> //TODO...
> }
> }
>
> int Main()
> {
> Test t;
> Test b = new Test();
>
> t += b; //Runtime exception because t is null
>
> }
You can access static class members through variables which are of that
class's type. This applies to all static methods and fields; static
operator overloads are no exception. I'm not entirely sure why you can do
this; it's probably "the way C++ does it."
That being said, I'm not sure why you decided to try a static overload
instead of just new'ing t. Another solution would be to make your multicast
delegate a struct type instead, which wouldn't have to be new'ed; I think
DFL (very .Net like form library for D) does this.
More information about the Digitalmars-d
mailing list