title: Template class override base class virtual function
body: <p>Consider the following code:</p>
  
  <pre><code>class Base
  {
  public:
      virtual void* allocate(){ return nullptr; }
  };
  
  template &lt;class T&gt; class BaseTemplate : public Base
  {
  public:
      void* allocate() override { return new T(); }
  };
  
  class IntSpecialization : public BaseTemplate&lt;int&gt;
  {
  };
  
  Base GetSpecialization(const int&amp;){ return IntSpecialization(); }
  </code></pre>
  
  <p>The goal is to be able to use template to implement specializations, but still allow users to work using the base class interface, such as:</p>
  
  <pre><code>int a;
  auto s = GetSpecialization(a);
  auto p = s.allocate();
  </code></pre>
  
  <p>The above code does not work; <code>s.allocate()</code> always return <code>nullptr</code> for obvious reasons.</p>
  
  <p>I absolutely need the <code>GetSpecialization</code> function to return the <code>Base</code> non-template class, so how do I go about this?</p>
  
  <p>The <code>Base</code> class virtual method cannot be pure, because otherwise it becomes abstract and it will fail the compilation at <code>GetSpecialization</code>.</p>
  
  <p>What is the best approach to solve this pattern? Using C++11?
  Thanks!</p>