Container implementation for complex type
<p>I'm trying to come up with a container wrapper which stores data of the following types: bool, int, double, std::string. In addition I have a complex type which I need to store in the container. Let's call it Foo. For the sake of simplicity we'll say that Foo contains a list of ints.</p>

<p>My container class currently wraps an ugly and complex container type which I get from a c api. When I'm finish manipulating the data in the container, I need to copy it back to the api. It uses unions and linked lists. It is possible that I can copy this data into, for example, a std::list, but this might cause performance issues which present themselves at a later date. Therefore, my container class is not dependant on how data is actually stored in memory.</p>

<p>Here's a quick idea of how my container looks:</p>

<pre><code>template &lt;class T&gt;
class Cont
{
public:
    Cont(ISetter&lt;T&gt;* setter)
        : _setter(setter)
    {
    }

    void sillyFunction(T t)
    {
        (*_setter)(t,0);
    }

private:
    ...
    ISetter&lt;T&gt;* _setter;
};
</code></pre>

<p>So I use a helper setter class which handles the nitty gritty of the memory. I have a number of these class but the ISetter will give you an idea of what I'm doing.</p>

<p>In order to deal with the Foo type, which is also stored by the c api in a rather bizarre way, I have arrived at the following setter. Again, this is just a rough example.</p>

<pre><code>class IFoo
{
public:
    virtual int getMember() = 0;
};

class Foo2: public IFoo
{
public:
    virtual int getMember(){ return 1;} // dummy 
};

template&lt;typename T&gt; class ISetter{};
template&lt;&gt; class ISetter&lt;IFoo*&gt;
{
public:
    virtual void operator()(IFoo* value, int index) = 0;
};

template&lt;typename T&gt; class Setter{};
template&lt;&gt; class Setter2&lt;Foo2*&gt;: public ISetter&lt;IFoo*&gt;
{
public:
    virtual void operator()(IFoo* value, int index)
    {
        _list[index] = dynamic_cast&lt;Foo2*&gt;(value);
    }

private:
    std::vector&lt;Foo2*&gt; _list;
};
</code></pre>

<p>So I handle my Foo as an interface called IFoo. The Setter2 implementation deals with the setting in memory of my list of Foos. Setter1, missing below, deals with the ugly c api memory.</p>

<p>Here's an idea of these class in practice:</p>

<pre><code>Foo2* f = new Foo2();
ISetter&lt;IFoo*&gt;* setter = new Setter2&lt;Foo2*&gt;();
Cont&lt;IFoo*&gt;* container = new Cont&lt;IFoo*&gt;(setter);
container-&gt;sillyFunction(f); 
</code></pre>

<p>When dealing with ints, for example, I do something like this instead:</p>

<pre><code>int i = 10;
ISetter&lt;int&gt;* setter = new Setter1&lt;int&gt;();
Cont&lt;int&gt;* container = new Cont&lt;int&gt;(setter);
container-&gt;sillyFunction(i);
</code></pre>

<p>So, my question is if you think this is a good approach and what improvements you might recommend. </p>

<p>I use shared pointers instead of raw pointers.</p>
