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 6095203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:47:10+00:00 2026-05-23T12:47:10+00:00

I am creating a template factory for my project, everything was working fine until

  • 0

I am creating a template factory for my project, everything was working fine until I need to add an extra parameter to the object creation process.

The factory has two main templates:

template <typename T>
class GenericFactory_c: boost::noncopyable
{
    public:
          typedef typename T::ObjectType_t ObjectType_t;

          //basic creating with just 1 parameter (object name)
          ObjectType_t Create(const String_c &className, const String_c &name) const
          {
              typename ObjectCreatorSet_t::const_iterator it = setObjectCreators.find(className, ObjectCreatorComp_s<T>());
              if(it == setObjectCreators.end())
                   PH_RAISE(OBJECT_NOT_FOUND_EXCEPTION, "[EntityFactory_c::Create]", name);

              return it->Create(name);
          }

          //"advanced" creation using an additional Y parameter
          template <typename Y>
          ObjectType_t Create(const String_c &className, const String_c &name, Y param) const
          {
              typename ObjectCreatorSet_t::const_iterator it = setObjectCreators.find(className, ObjectCreatorComp_s<T>());
              if(it == setObjectCreators.end())
                  PH_RAISE(OBJECT_NOT_FOUND_EXCEPTION, "[EntityFactory_c::Create]", name);

              return it->Create(name, param);
          }

          //rest of the code, probably irrelavent to the problem removed for clarity
};

The idea is that for certain types, only the create with 2 parameters will be used, for other types only the create with 3 parameters will be used.

That means that for a certain Factory instantiation, never both versions will be used, just one.

For being able to auto register types using static variables, I created a ObjectCreator class, this is defined as follows:

template <typename T, typename Y>
class ObjectCreatorBase_c: public ObjectCreatorAutoUnlinkHook_t
{
    public:
         typedef T ObjectType_t;
         typedef Y ObjectCreatorProc_t;

    public:
         ObjectCreatorBase_c(const String_c &name, ObjectCreatorProc_t proc):
             strName(name),
             pfnCreateProc(proc)
         {
         }

         T Create(const String_c &name) const
         {
             return pfnCreateProc(name);
         }

         template <typename Z>
         T Create(const String_c &name, Z param) const
         {
             return pfnCreateProc(name, param);
         }

     //"irrelevant" code removed

         private:
             String_c strName;
             ObjectCreatorProc_t pfnCreateProc;
};

And for a EntityComponent type that needs two parameters on construtor (string and Entity reference) I define an object creator as below:

template <typename T, typename Y>
class ObjectCreator1_c: public ObjectCreatorBase_c<T, T(*)(const String_c &, Y )>
{       
    public:
        ObjectCreator1_c(const String_c &name, ObjectCreatorProc_t proc):
            ObjectCreatorBase_c(name, proc)             
        {               
            GenericFactory_c<ObjectCreator1_c >::GetInstance().Register(*this);
        }
};

And a creator is defined liked this:

static ObjectCreator1_c<EntityComponentPtr_t, Entity_c &> CreatorForXYZ_CreatorObject_gl("XYZ", &XYZ::Create);

A factory for this is defined like:

typedef GenericFactory_c<ObjectCreator1_c<EntityComponentPtr_t, Entity_c &> > EntityComponentFactory_c;

And finally, for creating a component I use the code below:

Entity_c::CreateCompXYZ()
{
    EntityComponentFactory_c &factory = EntityComponentFactory_c::GetInstance();

    EntityComponentPtr_t xyz = factory.Create("XYZ", "myXYZInstance", *this);
}

And finally comes my problem, with the code above, the compiler appears to ignore the reference to the *this and tries to create a copy of the Entity object and I get a undefined reference to Entity_c::Entity_c(const Entity_c &), that is ok, because Entity_c does not have a copy constructor (non copyable), but the problem is because this code is not expected to try to copy Entity_c, but uses it references.

Any ideas?

  • 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-23T12:47:10+00:00Added an answer on May 23, 2026 at 12:47 pm

    If this function

    Entity_c::CreateCompXYZ()
    {
        EntityComponentFactory_c &factory = EntityComponentFactory_c::GetInstance();
    
        EntityComponentPtr_t xyz = factory.Create("XYZ", "myXYZInstance", *this);
    }
    

    is actually calling this template for a 3 parameter Create

    //"advanced" creation using an additional Y parameter
    template <typename Y>
    ObjectType_t Create(const String_c &className, const String_c &name, Y param) const
    

    it really is trying to copy Entity_c (it being Y here).

    Of course this doesn’t work if it is non-copyable!

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

Sidebar

Related Questions

For creating algorithm template function I need to know whether x or X (and
I am creating a template parser and i need to sort the array of
I am creating a Control Template for the Button control in Silverlight 2. I
I could use some help creating an XSL template that will take a string
I've been creating a nice T4 template for a repository pattern for my entities.
Have a tough one here! I'm creating a blogger template, and the client wants
I'm creating a template which produces output based on a single string, passed via
I'm creating a template with two different forms but I have the following problem:
We are creating a site template that among other things has a Document library
I know how to create a list template by creating from an existing list.

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.