I want to make a generic singleton class which I can create a is-a relationship with.
Looking around a bit I found something like this:
Would something like this work if I had two different classes say Foo and Bar which inherit from Singleton.Code:template <class T> Singleton{ protected: Singleton(); ~Singleton(); static T* m_pInstance; .... public: static T* getInstance(){....} };
Singleton<Foo>::getInstance()->FooFunc();
Singleton<Bar>::getInstance()->BarFunc();
I think it should work since there would be two versions of m_pInstance... the one for class Foo and one for class Bar...



1Likes
LinkBack URL
About LinkBacks


