Inheritance from std :: vector

There are many answers here suggesting not to inherit from std :: vector and similarly this question . I understand the reasons and agree with them. However, in Section 4.4.1.2 here, Bjarne Stroustrup itself inherits from std :: vector to add range checking.

Is this a special case or just what is good in this context or something that it really should not do: P

+6
source share
1 answer

I think this answer perfectly answers your question.

It is impossible to inherit from std::vector , it just probably will be very limited (due to the lack of a virtual destructor), rather confusing for others and expanding in composition, in any case it will be better / easier / more maintainable than inheritance.

Perhaps Stroustrup simply wanted to show it doable, but it does not have to mean that he offers it.

+3
source

Source: https://habr.com/ru/post/943517/


All Articles