Can we just have struct inheritence already?

Walter Bright newshound2 at digitalmars.com
Mon Jun 10 09:38:52 UTC 2019


On 6/9/2019 10:52 PM, Manu wrote:
> On Sun, Jun 9, 2019 at 9:50 PM Walter Bright via Digitalmars-d
> <digitalmars-d at puremagic.com> wrote:
>>
>> On 6/9/2019 1:05 AM, Manu wrote:
>>> I am really really tired of this pattern:
>>
>> Is your real complaint this:
>> ---
>>     #include <stdio.h>
>>
>>     struct B { };
>>     struct S : B { char c; };
>>     struct T { B b; char c; };
>>
>>     void main(){
>>       printf("%d %d\n", sizeof(struct S), sizeof(struct T));
>>     }
>> ---
>> which prints:
>>
>>     1 2
>>
>> ?
> 
> That is indeed the feature that necessitates my 'solution', but `alias
> this` is generally undesirable in this pattern in its own right, for
> some of the reasons I listed.

I don't see where you listed reasons? Other than it just being unsightly?

> `alias this` does not feel satisfying in this context in its own
> right. Also, if this hack takes the alias this slot, then it can't be
> used for what it's usually used for (enabling implicit conversion) and
> sometimes needs conflict.

Are you using 'alias this' to try to do multiple inheritance? Please don't :-(



More information about the Digitalmars-d mailing list