title: Understanding how a template function (with source in .h) relates to its compiled .lib
body: <p>Suppose I want to send a C++ class (without source) to my friend Bob.  I would send him a compiled .lib and the given MyClass.h:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>class MyClass {
    public:
      /// Public template function for safety of size, implementation in .h
      template &lt;class T&gt;
      static int SendData(const T&amp; data) {
          return SendDataUnsafe(&amp;data, sizeof(T));
      };
  
    private:
      /// Private function with risky size, code implementation in .cpp and compiled in .lib
      static int SendDataUnsafe(PCVOID data, size_t data_size);
  };
  </code></pre>
  
  <p>I understand that the source code of <code>SendDataUnsafe</code> in MyClass.cpp was compiled and partially linked into a MyClass64.lib (example).  Since it is private, the Bob's compiler won't let him call <code>SendDataUnsafe</code> directly (unresolved external).  So Bob must use the templated <code>SendData</code> instead.  But I have some questions:</p>
  
  <ol>
  <li><p>Is there anything compiled about the <code>SendData</code> template into the .lib, since the implementation is entirely in the .h?  </p></li>
  <li><p>Could Bob change the source code of <code>SendData</code> (in the .h) and replace <code>sizeof(T)</code> by something else to gain indirect access to <code>SendDataUnsafe</code>?</p></li>
  </ol>
  
  <p><strong>EDIT:</strong> If Bob removes the <code>private:</code> statement and tries to call <code>SendDataUnsafe</code>, he gets an ERROR (which seems in contradiction to comments received so far):</p>
  
  <pre><code>ERROR, LNK2019, unresolved external symbol "public: static int MyClass::SendDataUnsafe(void const *,unsigned __int64)" (...) referenced in function main
  </code></pre>