title: How to implement a member function outside of a template class declaration body?
body: <p>I have a template class that has a big member function in generic form, so it is not very easy to read it through.
  I decide to move this function outside of the class body, and implement it in a "<em>.cpp" file that with same name as the "</em>.hpp", but I can't pass the compiling.
  If I implement it in a specialized form rather than a generic form, it can be compiled/linked, even though it be saved in the "*.cpp" file too.</p>
  
  <p>The codes is following:</p>
  
  <p>ClassC.hpp:</p>
  
  <pre><code>#pragma once
  template &lt;typename T&gt;
  class ClassC {
  public:
     ClassC( T* p ) : d( p ) {};
     void show();
  private:
     T* d;
  };
  </code></pre>
  
  <p>ClassC.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "ClassC.hpp"
  #include "ClassD.hpp"
  using namespace std;
  
  // this is a specialized version, and can be compiled/linked.
  template &lt;&gt;
  void ClassC&lt;ClassD&gt;::show() {
     cout &lt;&lt; "This is a specialized ClassC." &lt;&lt; endl;
  };
  
  // this is my generic version, and can not be compiled.
  template &lt;typename T&gt;
  void ClassC::show() {
       cout &lt;&lt; "This is a generic ClassC." &lt;&lt; endl;
  };
  /* */
  </code></pre>
  
  <p>ClassD.hpp</p>
  
  <pre><code>#pragma once
  #include "ClassC.hpp"
  class ClassD {
  public:
     ClassD(): c( this ) {};
     void show();
  private:
     ClassC&lt;ClassD&gt; c;
  };
  </code></pre>
  
  <p>ClassD.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "ClassD.hpp"
  using namespace std;
  void ClassD::show() {
     c.show();
     cout &lt;&lt; "This is ClassD" &lt;&lt; endl;
  };
  </code></pre>
  
  <p>main.cpp</p>
  
  <pre><code>#include "ClassD.hpp"
  int main() {
     ClassD d;
     d.show();
     return 0;
  };
  </code></pre>