title: How do explicit template instantiations affect what the linker can find?
body: <p>See the following code and please clear my doubts.</p>
  
  <ol>
  <li><p>As ABC is a template, why does it not show an error when we put the definition of the ABC class member function in test.cpp?</p></li>
  <li><p>If I put test.cpp code in test.h and remve 2, then it works fine. Why?</p></li>
  </ol>
  
  <p>.</p>
  
  <pre><code>// test.h 
  template &lt;typename T&gt; 
  class ABC { 
  public: 
     void foo( T&amp; ); 
     void bar( T&amp; ); 
  }; 
  // test.cpp 
  template &lt;typename T&gt; 
  void ABC&lt;T&gt;::foo( T&amp; ) {} // definition 
  template &lt;typename T&gt; 
  void ABC&lt;T&gt;::bar( T&amp; ) {} // definition 
  
  template void ABC&lt;char&gt;::foo( char &amp; );  // 1 
  template class ABC&lt;char&gt;;                // 2 
  // main.cpp 
  #include "test.h" 
  int main() { 
     ABC&lt;char&gt; a; 
     a.foo();     // valid with 1 or 2 
     a.bar();     // link error if only 1, valid with 2 
  } 
  </code></pre>