There are many answers on here saying not to inherit from std::vector and alike such as this question. I understand the reasons and agree with them. However in here Section 4.4.1.2 Bjarne Stroustrup himself inherits from std::vector to add range checking.
Is that a special case, or just something that's ok in that context or something that he really ought not be doing :P
I think this answer perfectly answers your question.
It's not impossible to inherit from std::vector
, it just probably would be very limited (due to no virtual destructor), quite confusing to others and extending by composition would be better/easier/more maintainable than inheritance anyway.
Perhaps Stroustrup simply wanted to show it's doable, but not necessarily to imply that he suggests it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With