title: linking errors from static members
body: <p>sorry, if this gets a little complicated. I've taken the object and removed everything superfluous to narrow down the cause of the error. This is what's causing my error:</p>
  
  <p>d3d11module.h</p>
  
  <pre><code>#ifndef STUFF_H
  #define STUFF_H
  
  #include &lt;map&gt;
  #include &lt;string&gt;
  #include &lt;memory&gt;
  
  class D3D11
  {
  public:
      class Shader;
      template&lt;class T&gt;
      class ShaderRegister;
  
      typedef std::map&lt;std::string, std::shared_ptr&lt;Shader&gt;(*)()&gt; SHADER_CREATE_MAP;
  
  private:
      static SHADER_CREATE_MAP createMap;
  };
  
  class D3D11::Shader
  {
  
  };
  
  template&lt;class T&gt;
  std::shared_ptr&lt;D3D11::Shader&gt; createShader() {return std::shared_ptr&lt;D3D11::Shader&gt;(new T);}
  
  template&lt;class T&gt;
  class D3D11::ShaderRegister
  {
  public:
      ShaderRegister(std::string const &amp; s)
      {
          D3D11::createMap.insert(std::pair&lt;std::string,std::shared_ptr&lt;Shader&gt;(*)()&gt;(s, &amp;createShader&lt;T&gt;));
      }
  };
  
  #endif
  </code></pre>
  
  <p>just a real quick explanation of all this. There is a class called d3d11 that contains a couple of classes. First the shader class which classes are to be able to derive and implement, but is left blank here because it's contents have nothing to do with the problem. then i have a map of string indices, that correspond to function pointers.</p>
  
  <p>the ShaderRegister object is to be a static private member within the derived shader classes. Then just outside, the constructor is invoked so that a specified index and a pointer to createShader() is stored at that index. By doing this, invoking the index will call this templated function, returning an instance of that derived shader.</p>
  
  <p>I get the linking error though, when trying to derive the shader object and createing an instance of ShaderRegister and trying to call it's constructor. Take a look:</p>
  
  <pre><code>#ifndef DIFFUSE_SHADER
  #define DIFFUSE_SHADER
  
  #include "d3d11module.h"
  
  class DiffuseShader : public D3D11::Shader
  {
      static D3D11::ShaderRegister&lt;DiffuseShader&gt; reg;
  };
  
  D3D11::ShaderRegister&lt;DiffuseShader&gt; DiffuseShader::reg("DiffuseShader");
  
  #endif 
  </code></pre>
  
  <p>doing that causes a quite a painful looking link error. </p>
  
  <p><code>main.obj : error LNK2001: unresolved external symbol "private: static class std::map&lt;class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt;,class std::tr1::shared_ptr&lt;class D3D11::Shader&gt; (__cdecl*)(void),struct std::less&lt;class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt; &gt;,class std::allocator&lt;struct std::pair&lt;class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt; const ,class std::tr1::shared_ptr&lt;class D3D11::Shader&gt; (__cdecl*)(void)&gt; &gt; &gt; D3D11::createMap" (?createMap@D3D11@@0V?$map@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@P6A?AV?$shared_ptr@VShader@D3D11@@@tr1@2@XZU?$less@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@P6A?AV?$shared_ptr@VShader@D3D11@@@tr1@2@XZ@std@@@2@@std@@A)</code></p>
  
  <p>still, what i think it's trying to say is the static map object in the d3d11 class is undefined when used at some point. But i thought static objects were constructed at the beginning of the program. So what's going on?</p>