Can we just have struct inheritence already?

Manu turkeyman at gmail.com
Mon Jun 10 05:52:44 UTC 2019


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.
`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.


More information about the Digitalmars-d mailing list