I've been trying to build a Singleton template without having to change my (pretty sizable) code base. Right now, I'm passing pointers to the object to all game classes( gameObject, controllers, etc).
So, I built a singleton template. worked fine. Tried to operator overload "->". All hell broke loose >.>"
Template:
class Singleton{
private:
static T *singleClass;
public:
static T getInstance(){
if(singleClass == NULL)
singleClass = new T;
return *singleClass;
};
T Singleton::operator ->(){
if(singleClass == NULL)
singleClass = new T;
return (*singleClass);
}
};
--------------------------------------------------------------------------------------------------------------------------------------------Class using template:
class Model : public Singleton<Model>{
private:
bool enabled;
static b2World *world;
static float gameSpeedRatio;
float stepTime;
float numStepTurns;
contactListenerManager *contactManager;
b2Body *boundaryBody;
public:
.. \\normal interface
}
--------------------------------------------------------------------------------------------------------------------------------------------Error given byVisual Studio 2010:
1>Applicaton.obj : error LNK2001: unresolved external symbol "private: static class Model * Singleton<class Model>::singleClass" (?singleClass@?$Singleton@VModel@@@@0PAVModel@@A)
1>Model.obj : error LNK2001: unresolved external symbol "private: static class b2World * Model::world" (?world@Model@@0PAVb2World@@A)
--------------------------------------------------------------------------------------------------------------------------------------------
I know I'm doing something incredibly screwey, but I can't figure it out.
Thanks all!






