Boost logo

Boost :

From: Andy Tompkins (atompkins_at_[hidden])
Date: 2005-10-25 11:04:33


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?
Has this been done already?

Thanks in advance for any comments?
  Andy Tompkins


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk