Difference between choosing a subclass via a template parameter or instantiating a member variable
<p>Say I have a class that can use different types of distance functions (Euclidean distance, etc) to do some comparisons. I have implemented these functions as subclasses of a class Distance:</p>

<pre><code>class Distance;
class EuclideanDistance : public Distance;
class OtherDistance : public Distance;
</code></pre>

<p>It seems that to choose which type of distance to use, I could do:</p>

<pre><code>template &lt;typename TDistance&gt;
class MyClass;
</code></pre>

<p>and instantiate it with:</p>

<pre><code>MyClass&lt;EuclideanDistance&gt; instance;
</code></pre>

<p>or accomplish the same thing with:</p>

<pre><code>class MyClass
{
public:
 Distance* myDistanceFunction;
}
</code></pre>

<p>and instantiating it with</p>

<pre><code>MyClass instance;
instance.myDistanceFunction = new EuclideanDistance;
</code></pre>

<p>are there any advantages of one method over the other?</p>

<p>Thanks,</p>

<p>David</p>
