Can we just have struct inheritence already?

Manu turkeyman at gmail.com
Tue Jun 11 00:34:57 UTC 2019


On Mon, Jun 10, 2019 at 3:35 PM Max Haughton via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
>
> On Monday, 10 June 2019 at 21:59:51 UTC, Ola Fosheim Grøstad
> wrote:
> > On Monday, 10 June 2019 at 21:15:52 UTC, Walter Bright wrote:
> >> On 6/10/2019 7:42 AM, Andrei Alexandrescu wrote:
> >>> The same way it causes in C++. Crack open literally any C++
> >>> introductory book to find the explanation.
> >>
> >> Some reasons:
> >>
> >> https://stackoverflow.com/questions/4353203/thou-shalt-not-inherit-from-stdvector
> >
> > The answers with high rating actually state that there is no
> > problem in inheriting from std::vector…
> >
> >> https://stackoverflow.com/questions/2034916/is-it-okay-to-inherit-implementation-from-stl-containers-rather-than-delegate
> >
> > The most highly rated answer says that there is no problem with
> > inheriting from std::vector if you don't rely on on having a
> > virtual destructor…
> >
> > So, not the best source for building an argument.
>
> Just because the code is semantically correct or "safe" doesn't
> mean it's good code. Inheriting from a container that you either
> aren't directly extending or don't own is a huge code smell in my
> view

DRY. Base sets of members for consistency and minimising maintenance
between collections of things are unbelievably common.
DRY exists separately from polymorphism.



More information about the Digitalmars-d mailing list