title: Function pointers in C++ class constructor
body: <p>I have a templated class with a constructor which takes a single argument; a function pointer to a function that takes an argument of the second template-type. and returns an element of the first template-type.</p>
  
  <p>Here's the code:</p>
  
  <p>cache_controller.hpp:</p>
  
  <pre><code>template&lt;class TYPE, class KEY&gt;
  class cache
  {
      private:
          TYPE (*create_func)(KEY);
      public:
          cache(TYPE (*func)(KEY));
  };
  
  extern sf::Texture * create_texture(std::string path);
  </code></pre>
  
  <p>cache_controller.cpp:</p>
  
  <pre><code>template&lt;class TYPE, class KEY&gt;
  cache&lt;TYPE, KEY&gt;::cache(TYPE (*func)(KEY))
  {
      this-&gt;create_func = func;
  }
  
  sf::Texture * create_texture(std::string path)
  {
      sf::Texture * tex_p = new sf::Texture;
      tex_p-&gt;loadFromFile(path);
      return tex_p;
  }
  </code></pre>
  
  <p>Test code:</p>
  
  <pre><code>cache&lt;sf::Texture *, std::string&gt; tcache(&amp;create_texture);
  </code></pre>
  
  <p>However, when I link I get this error:</p>
  
  <pre><code>[Linker error] main.cpp:11: undefined reference to `cache&lt;sf::Texture*, std::string&gt;::cache(sf::Texture* (*)(std::string))' 
  </code></pre>
  
  <p>Of course, if there are any easier ways to implement an object cache with arbitary keys, values and creation functions I'm all ears.</p>