|
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 {
>public:
> ~virtual_vector();
> ...
>private:
> 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>
>{
>public:
> //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: http://lists.boost.org/mailman/listinfo.cgi/boost
Victor A. Wagner Jr. http://rudbek.com
The five most dangerous words in the English language:
"There oughta be a law"
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk