title: How to properly explicitly instantiate a template class with fully-specialized members?
body: <p>Let's say we have the following files:</p>
  
  <p>foo.h</p>
  
  <pre><code>namespace ns
  {
      template &lt;typename T&gt;
      class Foo
      {
      public:
          Foo();
  
          ~Foo();
  
          void DoIt();
      };
  }
  </code></pre>
  
  <p>foo.cpp</p>
  
  <pre><code>#include "foo.h"
  
  #include &lt;iostream&gt;
  
  namespace ns
  {
      template &lt;typename T&gt;
      Foo&lt;T&gt;::Foo() { std::cout &lt;&lt; "Being constructed." &lt;&lt; std::endl; }
  
      template &lt;typename T&gt;
      Foo&lt;T&gt;::~Foo() { std::cout &lt;&lt; "Being destroyed." &lt;&lt; std::endl; }
  
      template &lt;&gt;
      void Foo&lt;int&gt;::DoIt()
      {
          std::cout &lt;&lt; "Int" &lt;&lt; std::endl;
      }
  
      template &lt;&gt;
      void Foo&lt;double&gt;::DoIt()
      {
          std::cout &lt;&lt; "Double" &lt;&lt; std::endl;
      }
  
      template class Foo&lt;int&gt;;
      template class Foo&lt;double&gt;;
  }
  </code></pre>
  
  <p>Is that the correct way to do explicit instantiation, assuming the type will only ever be used with int or double as type parameters? Or do you need to declare the explicit specialization in the header file as well?</p>
  
  <p>Doing it the way I've shown works with visual studio, but a coworker has been having problems with GCC (Although I've just checked, and I think that's due to something else, but I'll post this question anyway)</p>