Can we just have struct inheritence already?
Olivier FAURE
couteaubleu at gmail.com
Tue Jun 18 18:39:41 UTC 2019
On Tuesday, 18 June 2019 at 12:17:36 UTC, Manu wrote:
> As base structs specifically. I really want struct inheritance,
> and
> zero sized fields does happen to be one thing that falls out of
> that.
> There are 2 things I hate about it; one is the crappy static-if
> hack
> required to deal with zero-sized bases, the other is that I
> have to
> use `alias this` to describe a base.
> alias this *should* be a very niche feature, but instead we
> abuse it
> in lieu of struct inheritance, and no way to perform implicit
> conversion. In both cases it's a gross code smell, and I hate
> it.
It might be because I write a lot less generic code than you do,
but I really don't understand why you lend so much importance to
implicit conversion.
XavierAP's question is particularly relevant here:
> What is the benefit of
>
> struct A { void fun(); };
> struct B :A {};
>
> B b;
> b.fun;
>
> compared to
>
> struct A {};
> struct B { A a; };
>
> B b;
> b.a.fun;
>
Like, seriously, I might be missing something, but I don't get it.
Can you cite some use case where inheritance is convenient but
composition isn't? Ideally an actual use case that came up in a
project?
More information about the Digitalmars-d
mailing list