Can we just have struct inheritence already?

Max Haughton maxhaton at gmail.com
Wed Jun 12 18:33:55 UTC 2019


On Tuesday, 11 June 2019 at 00:34:57 UTC, Manu wrote:
> 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:
>> >>> [...]
>> >>
>> >> 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.

I'm not against struct inheritance per se, I just don't agree 
with using it without careful thought. I was more thinking along 
the lines of inheriting from std::vector in c++  when it would 
clearly be better to have one as a member. For your use of it, I 
think it should exist in the language.


More information about the Digitalmars-d mailing list