Anonymous classes should pass through super ctors

Steven Schveighoffer schveiguy at yahoo.com
Mon Aug 18 09:10:44 PDT 2008


"Frank Benoit" wrote
> Bruno Medeiros schrieb:
>> Jarrett Billingsley wrote:
>>> "Frank Benoit" <keinfarbton at googlemail.com> wrote in message 
>>> news:g83v3k$n2u$1 at digitalmars.com...
>>>> Anonymous classes should pass through super ctors, if no ctor is given.
>>>>
>>>> class C {
>>>>    this( int i ){ .... }
>>>>    abstract void run();
>>>>    // ...
>>>> }
>>>>
>>>> auto c = new class(3) C {
>>>>    this( int a ){ super(a); } //<-- this line should not be necessary.
>>>>    void run(){}
>>>> };
>>>
>>> All classes should pass through super ctors.  :|
>>>
>>
>> Yes, if this was to be fixed/changed, it should be for all classes, not 
>> just anonymous ones.
>> I remember this issue (the automatic inheritance of ctors) being 
>> discussed before. What were the opinions of the community? And Walters? 
>> (I don't recall myself) If there was something approaching consensus, it 
>> might be worth opening a bug ticket.
>>
>
> Aren't anonymous classes a special case?
> Because they are only instantiated once with exactly those arguments given 
> in the declaration.

Yeah, but if you're going to have auto-inheritance of constructors, why not 
make it so I don't have to do this:

class Base
{
   this(int arg1, int arg2, char[] arg3, int arg4, float arg5) { ... }
}

class Derived : Base
{
   this(int arg1, int arg2, char[] arg3, int arg4, float arg5)
  {
      super(arg1, arg2, arg3, arg4, arg5);
  }
}

This can get annoying for a large hierarchy where you always want to inherit 
the base class' intiailization methods.

If we're going to get a way to do it for anonymous classes, I'd like it to 
be universal and consistent.

-Steve 





More information about the Digitalmars-d mailing list