Syntactic Sugar for Virtual Constructors?

Jarrett Billingsley kb3ctd2 at yahoo.com
Fri Feb 29 05:56:57 PST 2008


"Janice Caron" <caron800 at googlemail.com> wrote in message 
news:mailman.89.1204269640.2351.digitalmars-d at puremagic.com...
> On 29/02/2008, Christopher Wright <dhasenan at gmail.com> wrote:
>
>>  class Derived : AbstractBaseClass
>>  {
>>     static this ()
>>     {
>>        builders["whatever"] = { return new Derived1(); };
>>     }
>>  }
>
> Again, that would require the factory function to have compile-time
> knowledge of derived classes, which is precisely the thing to avoid.

Not necessarily.  If Derived were in a shared object, it would be loaded and 
then its static this() run, which would add itself to the list of builders 
in the base class, entirely at runtime. 





More information about the Digitalmars-d mailing list