title: C++ partial specialization in source file
body: <p>I have a problem concerning partial class template specialization in c++. I have one class A with two templates T,U. Then i want two class specializations with exclusive methods print_me(), only visible for those two specializations. Apart from that i need fully specialized member functions add_integer/add_double. When i implement those methods in the header file, it compiles fine. But id really like my implementations to be in the source file, which is no problem for the fully specialized functions, but for the partial ones. I get following errors for the code below:</p>
  
  <pre><code>test.h:27:25: error: declaration of ‘void A&lt;int, U&gt;::print_me()’ outside of class is not definition [-fpermissive]
  test.h:30:28: error: declaration of ‘void A&lt;double, U&gt;::print_me()’ outside of class is not definition [-fpermissive]
  </code></pre>
  
  <p>But if i leave out the declarations of print_me() in the header file i get an undefined reference error, which i understand, as my compiler cant know, which methods to instantiate when compiling.</p>
  
  <p>test.h:</p>
  
  <pre><code>//Primary Template Class
  template &lt;typename T, typename U&gt;
  class A{};
  
  //Partial Specialization 1
  template &lt;typename U&gt;
  class A&lt;int,U&gt;
  {
  public:
  void add_double(double a);
  void print_me();
  };
  
  //Partial Specialization 2
  template &lt;typename U&gt;
  class A&lt;double,U&gt;
  {
  public:
  void add_int(int a);
  void print_me();
  };
  
  //explicit specialization
  template &lt;&gt;
  void A&lt;int,double&gt;::add_double(double a);
  
  //explicit specialization
  template &lt;&gt;
  void A&lt;double,int&gt;::add_int(int a);
  
  //partial specialization
  template &lt;typename U&gt;
  void A&lt;int,U&gt;::print_me();
  
  //partial specialization
  template &lt;typename U&gt;
  void A&lt;double,U&gt;::print_me();
  </code></pre>
  
  <p>test.cpp</p>
  
  <pre><code>#include "test.h"
  
  template &lt;&gt;
  void A&lt;int,double&gt;::add_double(double a){}
  
  template &lt;&gt;
  void A&lt;double,int&gt;::add_int(int a){}
  
  
  template &lt;typename U&gt;
  void A&lt;int,U&gt;::print_me(){};
  
  template &lt;typename U&gt;
  void A&lt;double,U&gt;::print_me(){};
  </code></pre>
  
  <p>for testing purpose main.cpp</p>
  
  <pre><code>#include "test.h"
  
  int main()
  {
  A&lt;int,double&gt; * a_0=new A&lt;int,double&gt;;
  A&lt;double,int&gt; * a_1=new A&lt;double,int&gt;;
  
  a_0-&gt;add_double(1.1);
  a_0-&gt;print_me();
  
  a_1-&gt;add_int(1);
  a_1-&gt;print_me();
  
  return 0;
  }
  </code></pre>
  
  <p>So is there any possibility to have the print_me() methods implemented in the source file? Whats the difference between fully and partially specialized member functions in this context?</p>
  
  <p>Any hints will be appreciated</p>