What's the technical reason that class ctors aren't virtual?

Andrej Mitrovic andrej.mitrovich at gmail.com
Wed Aug 24 07:59:46 PDT 2011


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?


More information about the Digitalmars-d-learn mailing list