Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7189641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:20:42+00:00 2026-05-28T19:20:42+00:00

I have an Object Factory Class which has a method called registerCreator as defined

  • 0

I have an Object Factory Class which has a method called registerCreator as defined below:

template < class Base, class Key, typename ObjectCreator = Base* (*)()>

class ObjectFactory

{

      public:
        bool registerCreator( const Key& id, ObjectCreator creator)
        {
          return associations_.insert( typename IdToObjectMap::value_type(id, creator)).second != 0;
        }
        ...
      private:
        typedef std::map<Key, ObjectCreator> IdToObjectMap;
        IdToObjectMap associations_;

};

This class is wrapped in a singleton Holder which is essentially implemented following the Loki::SingletonHolder.

I have created a typedef to this as:

typedef SingletonHolder < ObjectFactory < AbstractResource, const char*, AbstractResource* (*)()> > ResourceFactory;

AbstractResource is an empty class for now.
I have used another ResourceBase class as follows to help with static polymorphism.

template <class DerivedType>
class ResourceBase
{
  public:
    virtual ~ResourceBase();
    static bool registerWithFactory();

  protected:

    ResourceBase();

  private:

    static const bool _Initialized;
};

// this also includes its .C implementation which is as follows:

template <class DerivedType>
const bool ResourceBase<DerivedType>::_Initialized = 
ResourceBase<DerivedType>::registerWithFactory();

template<class DerivedType>
bool ResourceBase<DerivedType>::registerWithFactory()
{
  if (! _Initialized)
  {
    return ResourceFactory::Instance().template registerCreator<DerivedType>    (DerivedType::className() , &DerivedType::allocate);
  }
}

and then my concrete class is as follows:
class FileManager : public ResourceBase, AbstractResource
{
public:
FileManager();
~FileManager() { }

    static const char* className();
    static AbstractResource* allocate();
};

With FileManager implementation as:

const char* FileManager::className()
{
    return "FileManager";
}

AbstractResource* FileManager::allocate()
{
  return new FileManager;
}

on compilation, I am getting:

error: no matching function for call to `ObjectFactory<AbstractResource, const char*, AbstractResource*(*)()>::registerCreator(const char*, AbstractResource*(*)())'

Can anyone please suggest what is the issue here? I am missing something very basic as it appears.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T19:20:43+00:00Added an answer on May 28, 2026 at 7:20 pm

    The problem is that you call registerCreator using the syntax to call a template member function of a class:

    return ResourceFactory::Instance()
           .template registerCreator<DerivedType>
           (DerivedType::className() , &DerivedType::allocate);
    

    However, registerCreator is a non-template member function of a template class. After the template class is instantiated (which you did, at the ResourceFactory definition), the non-template function does not need any additional specialization to be called. I.e. the following may work, as you can see at http://ideone.com/YIytS (courtesy of @Lol4t0).

    return ResourceFactory::Instance()
           .registerCreator (DerivedType::className() , &DerivedType::allocate);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a CustomerRelation class which has a method getInstance() and instance variable i.e
I have defined a method called ccy which takes in a number num ,
My situation is essentially this: I have a class called Foo which has dependencies
I have object A which in turn has a property of type Object B
I'm trying to create an EJB factory class, which works like this: You have
In apache.commons.collections there is a class called MapUtils which have these two methods to
I have a class which has a constructor that takes a const char* .
I have a factory class that populates objects with data. I want to implementing
I have a object built through a factory containing my parameters read from the
I have object A which contains multiple instances of object B, which in turn

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.