Static opDispatch

Jacob Carlborg doob at me.com
Sat Oct 1 09:34:50 PDT 2011


Have a look at the following code:

class Foo
{
     static Foo instance_;

     static Foo instance ()
     {
         if (instance_)
             return instance_;

         return instance_ = new Foo;
     }

     static auto opDispatch (string name, Args...) (Args args)
     {
         mixin("return instance." ~ name ~ "(args);");
     }

     void bar () {}
}

void main ()
{
     Foo.bar;
}

Compiling the above code results in:

Error: need 'this' to access member bar

Is it possible somehow to make the above code compile? If not, could the 
compiler be changed to make the above code compile?

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list