<p>In a <a href="https://stackoverflow.com/questions/168408/c-alternatives-to-void-pointers-that-isnt-templates">related question</a> I asked about creating a generic container. Using polymorphic templates seems like the right way to go.</p>

<p>However, I can't for the life of me figure out how a destructor should be written. I want the owner of the memory allocated to be the containers even if the example constructor takes in an array of <code>T</code> (along with its dimensions), allocated at some other point.</p>

<p>I would like to be able to do something like</p>

<pre><code>MyContainer&lt;float&gt; blah();
...
delete blah;
</code></pre>

<p>and</p>

<pre><code>MyContainer&lt;ComplexObjectType*&gt; complexBlah();
...
delete complexBlah;`
</code></pre>

<p>Can I do something like this? Can I do it without smart pointers?</p>

<p>Again, thanks for your input.</p>

It can be done, but this is pretty advanced stuff.
You'll need to use something like the boost MPL library (
http://www.boost.org/doc/libs/1_36_0/libs/mpl/doc/index.html
) so that you can get MyContainer's destructor to select the right kind of destructing it will need to do on individual items on the container. And you can use the boost TypeTraits library to decide what kind of deleting is required (
http://www.boost.org/doc/libs/1_36_0/libs/type_traits/doc/html/index.html
). I'm sure it will have a trait that will let you decide if your contained type is a pointer or not, and thus decide how it needs to be destructed. You may need to implement traits yourself for any other types you want to use in MyContainer that have any other specific deletion requirements. Good luck with it! If you solve it, show us how you did it.