Syntactic Sugar for Virtual Constructors?

Christopher Wright dhasenan at gmail.com
Fri Feb 29 19:17:42 PST 2008


Janice Caron wrote:
> 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.

You could try reading the code you're commenting on :P though there was 
a typo, I admit.

It was the derived class adding a delegate to a static array in the base 
class. The base class doesn't, technically speaking, know anything about 
any derived classes, and you don't get any of that circular dependency 
madness.



More information about the Digitalmars-d mailing list