From: Dave Harris (brangdon_at_[hidden])
Date: 2005-10-26 13:08:43
atompkins_at_[hidden] (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.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk