title: C++ One std::vector containing template class of multiple types
body: <p>I need to store multiple types of a template class in a single vector.</p>
  
  <p>Eg, for:</p>
  
  <pre><code>template &lt;typename T&gt;
  class templateClass{
       bool someFunction();
  };
  </code></pre>
  
  <p>I need one vector that will store all of:</p>
  
  <pre><code>templateClass&lt;int&gt; t1;
  templateClass&lt;char&gt; t2;
  templateClass&lt;std::string&gt; t3;
  etc
  </code></pre>
  
  <p>As far as I know this is not possible, if it is could someone say how?</p>
  
  <p>If it isn't  possible could someone explain how to make the following work?</p>
  
  <p>As a work around I tried to use a base, non template class and inherit the template class from it.</p>
  
  <pre><code> class templateInterface{
       virtual bool someFunction() = 0;
   };
  
   template &lt;typename T&gt;
   class templateClass : public templateInterface{
       bool someFunction();
   };
  </code></pre>
  
  <p>I then created a vector to store the base "templateInterface" class:</p>
  
  <pre><code>std::vector&lt;templateInterface&gt; v;
  templateClass&lt;int&gt; t;
  v.push_back(t);
  </code></pre>
  
  <p>This produced the following error:</p>
  
  <pre><code>error: cannot allocate an object of abstract type 'templateInterface'
  note: because the following virtual functions are pure within 'templateInterface'
  note: virtual bool templateInterface::someFunction()
  </code></pre>
  
  <p>To fix this error I made the function in templateInterface not a pure virtual by providing a function body, this compiled but when calling the function the overide is not used, but instead the body in the virtual function.</p>
  
  <p>Eg:</p>
  
  <pre><code> class templateInterface{
       virtual bool someFunction() {return true;}
   };
  
   template &lt;typename T&gt;
   class templateClass : public templateInterface{
       bool someFunction() {return false;}
   };
  
   std::vector&lt;templateInterface&gt; v;
   templateClass&lt;int&gt; i;
   v.push_back(i);
   v[0].someFunction(); //This returns true, and does not use the code in the 'templateClass' function body
  </code></pre>
  
  <p>Is there any way to fix this so that the overridden function is used, or is there another workaround to store multiple template types in a single vector?</p>