title: Inheriting from a virtual template class in C++
body: <p>How do I inherit from a virtual template class, in this code:</p>
  
  <pre><code>// test.h
  class Base {
   public:
    virtual std::string Foo() = 0;
    virtual std::string Bar() = 0;
  };
  
  template &lt;typename T&gt;
  class Derived : public Base {
   public:
    Derived(const T&amp; data) : data_(data) { }
  
    virtual std::string Foo();
    virtual std::string Bar();
  
    T data() {
      return data_;
    }
  
   private:
    T data_;
  };
  
  
  typedef Derived&lt;std::string&gt; DStr;
  typedef Derived&lt;int&gt; DInt;
  
  // test.cpp
  template&lt;typename T&gt;
  std::string Derived&lt;T&gt;::Foo() { ... }
  template&lt;typename T&gt;
  std::string Derived&lt;T&gt;::Bar() { ... }
  </code></pre>
  
  <p>When I try to use the DStr or DInt, the linker complain that there are unresolved externals, which are <code>Derived&lt;std::string&gt;::Foo()</code> and <code>Derived&lt;std::string&gt;::Bar()</code>, and the same for <code>Derived&lt;int&gt;</code>.</p>
  
  <p>Did I miss something in my code?</p>
  
  <p>EDIT:
  Thanks all. It's pretty clear now.</p>