Reputation: 30035
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
Upvotes: 8
Views: 9132
Reputation: 47543
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.
Upvotes: 4