Using template when none of the types have any code in common
<p>I have the following class:</p>

<pre><code>class ValueSetter: public IValueSetter
{
public:
    explicit ValueSetter(CContainer* container)
        : _container(container)
    {
    }

    virtual void operator()(const int value, const int index) const
    {
        _container-&gt;values[index].value.i = value;
    }

    virtual void operator()(const double value, const int index) const
    {
        _container-&gt;values[index].value.d = value;
    }

    virtual void operator()(const std::string&amp; value, const int index) const
    {
        ...
        _container-&gt;values[index].value.s = _strdup(value.c_str());
    }

private:
    CContainer* _container;
};
</code></pre>

<p>This class operates on CContainer which stores its data in a buffer of unions. I pass ValueSetter to a Container class which has no knowledge of CContainer. Indeed, in the future I'm hoping that CContainer (which I received via a C API) will disappear and that the values are instead organised in a std::vector or std::list. My Container's interface shouldn't need to change because of this and shouldn't care about how the data is stored in memory.</p>

<p>With this in mind, I'd prefer instead something roughly along these lines:</p>

<pre><code>class IntValueSetter: public IIntValueSetter
{
public:
    explicit IntValueSetter(Container* container)
        : _container(container)
    {
    }

    virtual void operator()(const int value, const int index) const
    {
        _container-&gt;values[index].value.i = value;
    }
private:
    CContainer_3* _container;
}
</code></pre>

<p>or:</p>

<pre><code>class IntValueSetter: public IIntValueSetter
{
public:
    explicit IntValueSetter(std::vector&lt;int&gt; values)
        : _values(values)
    {
    }

    ... 
}
</code></pre>

<p>but I'd need to be able to use them as follows:</p>

<pre><code>ValueSetter&lt;int&gt; valueSetter;
</code></pre>

<p>instead of </p>

<pre><code>IntValueSetter valueSetter;
</code></pre>

<p>How can I do this? </p>
