constructor inheritance
Sean Kelly
sean at invisibleduck.org
Tue Mar 4 15:26:09 PST 2008
== Quote from Simen Kjaeraas (simen.kjaras at gmail.com)'s article
> On Tue, 04 Mar 2008 22:25:15 +0100, Robert Fraser
> <fraserofthenight at gmail.com> wrote:
> > How about just:
> >
> > class Child : Parent
> > {
> > this(int x, int y)
> > {
> > super(x, y);
> > // Do anything else here if you want
> > }
> > }
> That does of course work, but if you have 15 different constructors, and
> most of them are identical to those of the base class, the template mixin
> is simpler and cleaner.
Template mixin requires the creator of the base class to have planned ahead, however. In D 2.0 it may
be possible to fake this using a string mixin and the new type attributes stuff, but I think the idea of
inheritable ctors provides enough general utility that it should be a language feature. As mentioned in
my original proposal, it provides for an entirely new programming idiom (new to my knowledge
anyway).
Sean
More information about the Digitalmars-d
mailing list