Note that there are some explanatory texts on larger screens.

plurals
  1. POC++: Templates - No Matching Function to call
    text
    copied!<p>I have an Object Factory Class which has a method called registerCreator as defined below:</p> <pre><code>template &lt; class Base, class Key, typename ObjectCreator = Base* (*)()&gt; class ObjectFactory { public: bool registerCreator( const Key&amp; id, ObjectCreator creator) { return associations_.insert( typename IdToObjectMap::value_type(id, creator)).second != 0; } ... private: typedef std::map&lt;Key, ObjectCreator&gt; IdToObjectMap; IdToObjectMap associations_; }; </code></pre> <p>This class is wrapped in a singleton Holder which is essentially implemented following the Loki::SingletonHolder.</p> <p>I have created a typedef to this as:</p> <pre><code>typedef SingletonHolder &lt; ObjectFactory &lt; AbstractResource, const char*, AbstractResource* (*)()&gt; &gt; ResourceFactory; </code></pre> <p>AbstractResource is an empty class for now. I have used another ResourceBase class as follows to help with static polymorphism.</p> <pre><code>template &lt;class DerivedType&gt; class ResourceBase { public: virtual ~ResourceBase(); static bool registerWithFactory(); protected: ResourceBase(); private: static const bool _Initialized; }; </code></pre> <p>// this also includes its .C implementation which is as follows:</p> <pre><code>template &lt;class DerivedType&gt; const bool ResourceBase&lt;DerivedType&gt;::_Initialized = ResourceBase&lt;DerivedType&gt;::registerWithFactory(); template&lt;class DerivedType&gt; bool ResourceBase&lt;DerivedType&gt;::registerWithFactory() { if (! _Initialized) { return ResourceFactory::Instance().template registerCreator&lt;DerivedType&gt; (DerivedType::className() , &amp;DerivedType::allocate); } } </code></pre> <p>and then my concrete class is as follows: class FileManager : public ResourceBase, AbstractResource { public: FileManager(); ~FileManager() { }</p> <pre><code> static const char* className(); static AbstractResource* allocate(); }; </code></pre> <p>With FileManager implementation as:</p> <pre><code>const char* FileManager::className() { return "FileManager"; } AbstractResource* FileManager::allocate() { return new FileManager; } </code></pre> <p>on compilation, I am getting:</p> <pre><code>error: no matching function for call to `ObjectFactory&lt;AbstractResource, const char*, AbstractResource*(*)()&gt;::registerCreator(const char*, AbstractResource*(*)())' </code></pre> <p>Can anyone please suggest what is the issue here? I am missing something very basic as it appears.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload