Jump to content
  • Advertisement
Sign in to follow this  
KH

Problems with implementation of pluggable factory

This topic is 4996 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im having some trouble trying to implement a pluggable factory. The concrete makers have a static instance of themselves that is supposed to be constructed during static initialization but this is not happening for some reason. class CircleMaker : public ShapeMaker { private: static const CircleMaker registerThis; CircleMaker() : ShapeMaker("Circle") {}; ... ShapeMaker::ShapeMaker(string className) { registry.insert( make_pair(className, this) ); } Any ideas why? or maybe other ways to solve this?

Share this post


Link to post
Share on other sites
Advertisement
Hi,

I believe this has to do with the fact that statics are created when first referenced.

Some Singleton implementations use a static singleton inside a function body. Only when you actually try to get the singleton will it be instantiated:


Single&
GetInstance ()
{
static Single sInstance;
return sInstance;
}


Before the first call to GetInstance, sInstance just doesn't exist.

hth,
CipherCraft

Share this post


Link to post
Share on other sites
In implementation file you have to add this line:
const CircleMaker::CircleMaker registerThis;

(maybe const will raise a compiler error, I think you can remove const both in header and in implementation file).

Hope this helps. :)

Share this post


Link to post
Share on other sites
Thanks for the help, adding the const CircleMaker CircleMaker::registerThis; got things going.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!