Template class and inheritance
Hi, maybe someone can help with this one...
I have a templated singleton class from which some manager derives
template<class S> class Singleton
{
private:
static S * SingletonInstance;
public:
static S* Instance()
{
if (SingletonInstance == NULL)
{
SingletonInstance = new S();
}
return SingletonInstance;
}
};
Let's say I have one AbstractManager that derives from this singleton,
and a ConcreteManager that derives from AbstractManager. The only way
I found to make this work is having the AbstractManager be a template
class, like this :
template<class R> class AbstractManager: public Singleton<R>
{
friend class Singleton<R>;
}
and
class ConcreteManager : public AbstractManager<OpenGLRenderer>
{
friend class Singleton<OpenGLRenderer>;
}
Which is unfortunate because I can't declare non abstract virtual
methods in AbstractManager. I can't also have pointers to the base
AbstractManager class on the ConcreteClass. For example, with code
like this :
Core::AbstractManager<ConcreteManager> * Mgr =
Core::ConcreteManager::Instance();
Mgr->MethodDeclaredInAbstractManager();
The compiler complains with :
unresolved external symbol "public: void __thiscall
AbstractManager<class
ConcreteManager>::MethodDeclaredInAbstractManager()"
Even if the method was declared and implemented in AbstractManager.
So, how should I handle multi-level inheritance from a classe that is
templated?
Thanks! :)
Simon