
In-Reply-To: <1130256273.28161.245978560@webmail.messagingengine.com> atompkins@fastmail.fm (Andy Tompkins) wrote (abridged):
I have read a few times that people sometimes wish that std::vector (or other containers) had a virtual destructor.
Generally when I've wished for that I've also wished for a few other virtual functions. For example, a hook which gets called whenever an item is added to the vector, and another which is called when items are removed. I think a vector which is designed to be derived from would need more than just a virtual destructor. If you are adding a vtable you might as well get some milage out of it. On the other hand, I rarely need my container to be polymorphic - at least, not with respect to some library base class like std::vector or boost::virtual_vector. Nor do I usually want my container to have the entire interface of vector. For example, I may not want to allow arbitrary insertion at all. So I tend to write a custom wrapper class that has vector as a private member and just exposes what I need. In general inheriting from anything in the std library has the drawback that it injects unknown junk names into your class. Inheriting from a boost class is hardly better. So overall, I'm not in favour. -- Dave Harris, Nottingham, UK.