title: C++ template function, same type, multiple instantiations: shares one same copy of code? EVEN in different cpp/object files
body: <p>For example, consider the following code:</p>
  
  <pre><code>// f.h
  template &lt;typename T&gt;
  int f(T x) {
     return x+1;
  }
  </code></pre>
  
  <p>If we instantiate it in both <code>foo.cpp</code> and <code>bar.cpp</code>:</p>
  
  <pre><code>//foo.cpp instantiation:
  int i = f(1);
  </code></pre>
  
  <p>and</p>
  
  <pre><code>//bar.cpp instantiation:
  int j = f(2);
  </code></pre>
  
  <p>Will the final program uses only one copy of code? Is that so, when <code>bar.cpp</code> is hidden but only the object file <code>bar.o</code> is provided?</p>
  
  <p>I think, since each cpp files are compiled independently, both <code>foo.o</code> and <code>bar.o</code> must contains <code>f(int)</code>.  The linker should see same duplicate signature, and use only one copy.  Am I right?</p>