title: C++ member function explicit template instantiation across DLL
body: <p>I am creating a <code>DLL</code> in <code>C++</code> using <code>Visual Studio 2013</code> on <code>Windows 8.1 Update 1</code>.
  There is a class called <code>XMLData</code> which has a public member function called <code>getAttribute</code>.</p>
  
  <p><strong>XMLData.h</strong></p>
  
  <pre><code>namespace DDGL
  {
      class DLL_EXPORTED XMLData
      {
  
         ...
  
         // const char* is used to avoid problems with trying to pass an
         // std::string over DLL boundaries
         template &lt;typename Type&gt; Type getAttribute (const char* attribute) const;
  
         ...
  
      };
  }
  </code></pre>
  
  <p>Inside the DLL, every use is instantiated as you'd expect and works fine.</p>
  
  <p>However, inside an application I will of course get undefined references for the <code>&lt;typename Type&gt;</code>'s that haven't been used within the DLL.</p>
  
  <p>So, I try to use explicit template instantiation (I'd rather not put the implementation in header, for a learning exercise if anything):</p>
  
  <p><strong>XMLData.cpp</strong></p>
  
  <pre><code>namespace DDGL
  {
  
      ...
  
      // getAttribute definition
  
      ...
  
      template float XMLData::getAttribute(const char* attribute) const;
  
      ...
  
  }
  </code></pre>
  
  <p>However, I still get an unresolved external in the application using the DLL:</p>
  
  <p><strong>Output</strong></p>
  
  <pre><code>error LNK2019: unresolved external symbol "public: float __thiscall DDGL::XMLData::getAttribute&lt;float&gt;(char const *)const " (??$getAttribute@M@XMLData@DDGL@@QBEMPBD@Z) referenced in function "class std::shared_ptr&lt;class DDGL::IGameObject&gt; __cdecl SimpleExplodingRocketDeserialiser(class DDGL::XMLData)" (?SimpleExplodingRocketDeserialiser@@YA?AV?$shared_ptr@VIGameObject@DDGL@@@std@@VXMLData@DDGL@@@Z)
  </code></pre>
  
  <p><strong>DLL_EXPORTED</strong></p>
  
  <pre><code>#ifdef DDGL_DLL_BUILDING
      #define DLL_EXPORTED __declspec(dllexport)
  #else
      #define DLL_EXPORTED __declspec(dllimport)
  #endif
  </code></pre>
  
  <hr/>
  
  <p>Where am I going wrong?</p>