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

  • SEARCH
  • Home
  • 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 832747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:24:35+00:00 2026-05-15T04:24:35+00:00

I have a class factory where I’m using variadic templates for the c’tor parameters

  • 0

I have a class factory where I’m using variadic templates for the c’tor parameters (code below). However, when I attempt to use it, I get compile errors; when I originally wrote it without parameters, it worked fine.

Here is the class:

template< class Base, typename KeyType, class... Args >
class GenericFactory
{
public:
   GenericFactory(const GenericFactory&) = delete;
   GenericFactory &operator=(const GenericFactory&) = delete;

   typedef Base* (*FactFunType)(Args...);

   template <class Derived>
   static void Register(const KeyType &key, FactFunType fn)
   {
      FnList[key] = fn;
   }

   static Base* Create(const KeyType &key, Args... args)
   {
      auto iter = FnList.find(key);
      if (iter == FnList.end())
         return 0;
      else
         return (iter->second)(args...);
   }

   static GenericFactory &Instance() { static GenericFactory gf; return gf; }
private:
   GenericFactory() = default;

   typedef std::unordered_map<KeyType, FactFunType> FnMap;
   static FnMap FnList;
};

template <class B, class D, typename KeyType, class... Args>
class RegisterClass
{
public:
   RegisterClass(const KeyType &key)
   {
      GenericFactory<B, KeyType, Args...>::Instance().Register(key, FactFn);
   }
   static B *FactFn(Args... args)
   {
      return new D(args...);
   }
};

Here is the error: when calling (e.g.)

// Tucked out of the way
RegisterClass<DataMap, PDColumnMap, int, void *> RC_CT_PD(0);

GCC 4.5.0 gives me:

In constructor 'RegisterClass<B, D, KeyType, Args>::RegisterClass(const KeyType&) [with B = DataMap, D = PDColumnMap, KeyType = int, Args = {void*}]':
no matching function for call to 'GenericFactory<DataMap, int, void*>::Register(const int&, DataMap* (&)(void*))'

I can’t see why it won’t compile and after extensive googling I couldn’t find the answer. Can anyone tell me what I’m doing wrong (aside from the strange variable name, which makes sense in context)?

  • 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-15T04:24:36+00:00Added an answer on May 15, 2026 at 4:24 am

    I think it’s barfing here:

    template <class Derived> 
    static void Register(const KeyType &key, FactFunType fn) 
    { 
       FnList[key] = fn; 
    } 
    

    You don’t use Derived in this function, but it’s probably messing up gcc’s attempt to resolve GenericFactory<...>.Register(...). You might also want to change that to GenericFactory<...>::Register(...).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.