super constructors question

Serg Kovrov kovrov at no.spam
Mon Aug 14 12:15:56 PDT 2006


BCS wrote:
> The major problem I see with this is say you have:
> 
> class Foo
> {
>     this(){...}
>     this(char){...}
>     this(char[]){...}
>     ... // 27 more constructors
> }
> 
> class Bar : Foo
> {
>     // all constructors implicit
> }
> 
> Now add one constructor to Bar.
> All of the implicit constructors vanish. Have fun tracking that all down.
> 
> Implicit constructors violate the idea that "simple changes should be 
> simple" (my position).
> 
> a Better solution might be to allow:
> 
> class Bar:Foo
> {
>     alias super(char[]);
>      // shorthand for: this(char[] arg){super(arg)};
> }

Currently there is no implicit super constructors calls at all, thats 
the problem. Explicitly defining aliases (just like duplication of dumb 
ctors calling supers) is not a solution. Because if base class changed 
signatures for its constructors or add new one, you must fix *all* class 
hierarchy. And compiler not allays will give you a hint. If hierarchy is 
big enough chances very high that you miss something.

PS. moved from digitalmars.D.learn to digitalmars.D
-- 
serg.



More information about the Digitalmars-d mailing list