title: Separate .h and .cpp files in template class implementation
body: <p>I am trying to write a template class that can form classes depending on the <code>&lt;class&gt;</code> I pass. The problem is I cannot declare and define in the same <code>.h</code> file. In my project, the UTF tool can only work with the <code>.cpp</code> files (for code coverage, etc.). I have seen in a blog that they say “Add <code>.cpp</code> instead of <code>.h</code>”. Is this advisable? </p>
  
  <p><code>Template.h</code></p>
  
  <pre><code>#ifndef TEMPLATE_H_
  #define TEMPLATE_H_
  
  template&lt;class T&gt;
  class Template
  {
  public:
      T Add(T a,T b);
  };
  
  #endif /* TEMPLATE_H_ */
  </code></pre>
  
  <p><code>Template.cpp</code></p>
  
  <pre><code>#include "Template.h"
  
  template&lt;class T&gt;
  T Template&lt;T&gt;::Add(T a, T b)
  {
      return a+b;
  }
  </code></pre>
  
  <p><code>Main.cpp</code></p>
  
  <pre><code>#include "Template.cpp" //Is this a good practise? 
  #include &lt;iostream&gt;
  
  int main(int argc, char **argv) {
      Template&lt;int&gt; obj;
      std::cout&lt;&lt;obj.Add(3,4)&lt;&lt;std::endl;
  }
  </code></pre>
  
  <p>If this is not advisable then how do I solve this issue? <code>export</code>?</p>