title: Abstract template class with pure virtual method in c++
body: <p>public/Interface.h</p>
  
  <pre><code>#pragma once
  
  template &lt;typename T&gt;
  class BaseInterface {
  public:
      virtual void foo() = 0;
  };
  </code></pre>
  
  <p>private/Base.h</p>
  
  <pre><code>#pragma once
  #include "../public/Interface.h"
  
  template &lt;typename T&gt;
  class Base : public BaseInterface&lt;T&gt; {
  public:
     virtual void foo() override;
  };
  
  template &lt;typename T&gt;
  inline void Base&lt;T&gt;::foo() {
  }
  </code></pre>
  
  <p>main.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;memory&gt;
  #include "public/Interface.h"
  
  int main() {
      auto base = std::make_shared&lt; BaseInterface&lt;std::string&gt; &gt;();
      base-&gt;foo();
      return 0;
  }    
  </code></pre>
  
  <p>Getting this error:</p>
  
  <pre><code>/usr/include/c++/5/ext/new_allocator.h:120:4: error: invalid new-expression of abstract class type ‘BaseInterface&lt;std::__cxx11::basic_string&lt;char&gt; &gt;’
    { ::new((void *)__p) _Up(std::forward&lt;_Args&gt;(__args)...); }
  
  AbstractPureVirtual/public/Interface.h:4:7: note:   because the following    virtual functions are pure within ‘BaseInterface&lt;std::__cxx11::basic_string&lt;char&gt; &gt;’:
   class BaseInterface {
  
  AbstractPureVirtual/public/Interface.h:6:17: note:  void BaseInterface&lt;T&gt;::foo() [with T = std::__cxx11::basic_string&lt;char&gt;]
  virtual void foo() = 0;
  </code></pre>
  
  <p>I get this error though I have overridden the pure virtual method in the Derived Class and seems like it is expected as its a template class. If I need to do something similar, how should I go about implementing this?</p>