title: C++ destruction list
body: <p>I have a class to do a computation using some callbacks. those callbacks need to allocate data (dynamic arrays) that needs to live outside of the callback scope but not after the class destructs. I thought about make a <code>vector</code> of <code>auto_ptr</code> that will just get destructed automatically when the class destructs:</p>
  
  <pre><code>class MyClass
  {
      vector&lt;auto_ptr&lt;MyObject&gt;&gt; ThingsToDie;
  };
  </code></pre>
  
  <p>The problem is I have a lot of objects allocated and they don't share a base type so I can't use one <code>vector</code> for this, and making a vector for every type is a lot of work.<br>
  A hierarchy like the following:</p>
  
  <pre><code>auto_ptr_base (virtual destructor)
        |
   auto_ptr&lt;T&gt;
  </code></pre>
  
  <p>Will solve my problem because I could do something like</p>
  
  <pre><code>class MyClass
  {
      vector&lt;auto_ptr_base&gt; ThingsToDie;
  };
  </code></pre>
  
  <p>and the destruction will be virtually dispatched to each specialized type automatically.<br>
  The problem is that the STL doesn't have that hierarchy and I don't want to re-implement auto_ptr.<br>
  Is there any other solution for this?</p>