So, I'm trying to create a singleton base template class so I can simulate XNA game services by allowing a class to be initialized only once, and by allowing that class to be added to a linked list of similar base objects.
The only solution I found to this problem was to create a singleton base template class, and create a static linked list of the base class to keep track of the services.
...This is proving to be more of a problem than anything, and here is why:
Singleton.h
ApplicationManager.hCode:template <class T> class Singleton { public: ~Singleton(void) {}; static T& GetService(void) {return *Instance;} protected: Singleton<T>(void) {}; static T* Instance; };
Code:#include "application.h" #include "singleton.h" class ApplicationManager : public Singleton<ApplicationManager> { public: Application* ActiveApplication(void) {return _ActiveApplication;} ~ApplicationManager(void); private: ApplicationManager(void); ApplicationManager(Application* app); Application* _ActiveApplication; };
The line in my main method:
The above line gives me the following external error:Code:ApplicationManager Prog = ApplicationManager::GetService();
LNK2001: unresolved external symbol "protected: static class ApplicationManager *Singleton<class ApplicationManager>::Instance"
What I was trying to do here, was to simply pass a single copy of the class into ApplicationManager prog.
Does anyone see the problem? Or does anyone know of a better/more elegant solution to this?



LinkBack URL
About LinkBacks



