Anonymous classes should pass through super ctors

Steven Schveighoffer schveiguy at yahoo.com
Mon Aug 18 11:44:31 PDT 2008


"BCS" <ao at pathlink.com> wrote in message 
news:55391cb330b528cacf3c1a094fc2 at news.digitalmars.com...
> Reply to Steven,
>
>> "BCS" wrote
>>
>>> Reply to Bruno,
>>>
>>>> I don't see how this could be dangerous in any way whatsoever, if
>>>> the
>>>> ctor inheritance rules followed the same rules as method inheritance
>>>> rules:
>>>> * if you don't override or overload any ctor in the overload set,
>>>> then
>>>> the whole overload set is available in the child class.
>>>> * if you do override or overload any ctor, well... follow the same
>>>> rules
>>>> as overriding/overloading a method.
>>> There needs to be an easy way to forbid one, several or all base
>>> constructors.
>>>
>> If you want to forbid all constructors, make a private constructor in
>> the derived class.  Due to the scope resolution rules of D, only the
>> most derived class' counts, unless you alias the parent's.
>>
>
> yup
>
>> If you want to forbid one, then you have to forbid it the same way you
>> do normal methods, implement all the ones you don't want to forbid.
>>
>
> one option would be:
>
> private this(/* the signiture *){assert(false);} // forbid this
> alias this this; // get everything else

Good, I think this would work with the current rules of overloading.

>
>>> And while were at it, it would be nice to add an auto constructor
>>> that is added to all constrictors (kind of like member variable
>>> initialization in c#)
>>>
>> It would be nice to be able to do this with runtime constructs,
>> instead of being limited to compile-time ones.
>>
>
> I'm not following...

i.e. you can already do this today:

class X
{
   int blah = 5;
}

But it has to be a compile-time constant.

It would be nice if you could use a runtime evaluated value.

-Steve 





More information about the Digitalmars-d mailing list