What's the technical reason that class ctors aren't virtual?
Jacob Carlborg
doob at me.com
Wed Aug 24 09:23:19 PDT 2011
On 2011-08-24 16:59, Andrej Mitrovic wrote:
> class Foo
> {
> this(int x, int y) { }
> }
>
> class Bar : Foo
> {
> }
>
> Bar has to define its own ctor even if it only forwards the call to
> the super() ctor, e.g.:
>
> class Bar : Foo
> {
> this(int x, int y) { super(x, y); }
> }
>
> But I'm curious why this works this way. If I have a large inheritance
> tree of classes and I want to change the base class ctor (say I want
> to add another int as a parameter), I'll have to change all the ctors
> in the subclasses as well.
>
> Isn't that counterproductive?
You can use a template mixin as a workaround.
--
/Jacob Carlborg
More information about the Digitalmars-d-learn
mailing list