super constructors question

Jarrett Billingsley kb3ctd2 at
Sun Aug 13 12:58:24 PDT 2006

"Serg Kovrov" <kovrov at no.spam> wrote in message 
news:ebn850$3qa$1 at
> Hello everybody,
> Could someone explain why D do not lookup for appropriate super
> constructor? It is in specs:
>> If there is no constructor for a class, but there is a constructor  for 
>> the base class, a default constructor of the form:
>> this() { }

That really should read "this() { super(); }".

> But i do not understand intension. Is it so hard for compiler to find
> suitable constructor in base class(es)?

It's not really trivial.  Basically the rule would have to change so that if 
a class were defined without any ctors, it would have to create a ctor for 
each ctor that the base class has, and forward the parameters.  So your code 
would insert an implicit "this(char[] name) {super(name);}" in FooBar.  That 
seems like a little too much automation for very rarely any real benefit. 
Most of the time you're going to be making new constructors for the derived 
class anyway, so it's kind of a niche problem. 

More information about the Digitalmars-d-learn mailing list