title: Is a template class compiled more than once in different compilation units in C++?
body: <p>Let's say I have the following code:</p>
  
  <pre><code>// templateClass.h
  #ifndef TEMPLATE_CLASS_H
  #define TEMPLATE_CLASS_H
  
  template &lt;typename T&gt;
  class tClass
  {
  public:
    tClass();
  };
  
  #endif
  
  // templateClassDef.inl
  #ifndef TEMPLATE_CLASS_DEF_INL
  #define TEMPLATE_CLASS_DEF_INL
  
  template &lt;typename T&gt;
  tClass&lt;T&gt;::tClass()
  {
  }
  
  #endif
  
  // normalClass.h
  #include "templateClass.h"
  
  class normal
  {
  public:
    normal();
  };
  
  // normalClass.cpp
  #include "normalClass.h"
  #include "templateClassDef.inl"
  
  normal::normal()
  {
    tClass&lt;int&gt; a;
  }
  
  // main.cpp
  #include "templateClass.h"
  #include "templateClassDef.inl"
  
  #include "normalClass.h"
  
  int main()
  {
    tClass&lt;int&gt; a;
    normal b;
  
    return 0;
  }
  </code></pre>
  
  <p>Note that the <code>inl</code> file is NOT being included in the header as it normally is, but is instead included in the source files (I am aware that is not the standard way... this is just an example). Notice that <code>normalcClass.cpp</code> is instantiating <code>tClass&lt;int&gt;</code> and so is <code>main.cpp</code>.</p>
  
  <p>I am curious as to whether the compiler has to construct the instantiation from the template class every time it encounters an explicit instantiation, considering it is the same type (i.e. <code>tClass&lt;int&gt;</code>) <em>even though</em> both instantiations occur in separate translation units (<code>normalClass.cpp</code> and <code>main.cpp</code>)? Also, will this increase in compile time (If the answer to the previous question is <em>yes it will instantiate it again</em> then this should also be <em>yes</em>)?</p>