Boost logo

Boost :

From: Victor A. Wagner Jr. (vawjr_at_[hidden])
Date: 2005-10-25 23:35:53

At 10:04 2005-10-25, Andy Tompkins wrote:
>I have read a few times that people sometimes wish that std::vector (or
>other containers) had a virtual destructor. I have recently wished
>for the same thing and I fairly quickly write a class called
>virtual_vector something like:
>template <class Type, class Allo = std::allocator<Type> >
>class virtual_vector {
> ~virtual_vector();
> ...
> std::vector<Type, Alloc> m_vector;
>All the public methods of std::vector are present in virtual_vector and
>are just forwarded on m_vector.
>This allows one to write something like:
>struct person {
> string first_name;
> string last_name;
>class people : public virtual_vector<person>
> //extra methods
>Is this useful?

unless I mis-read (or mis-understood...far more likely) a lot of
books on how C++ works, I don't believe there is any reason for what
_you've_ shown to need a virtual destructor. Until your derived
class needs a non-trivial destructor it won't matter one way or
another. Specifically, simply adding methods shouldn't create the
need for a non-trivial destructor.

>Has this been done already?
>Thanks in advance for any comments?
> Andy Tompkins
>Unsubscribe & other changes:

Victor A. Wagner Jr.
The five most dangerous words in the English language:
               "There oughta be a law"

Boost list run by bdawes at, gregod at, cpdaniel at, john at