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 * SingletonInstan ce;
public:
static S* Instance()
{
if (SingletonInsta nce == NULL)
{
SingletonInstan ce = new S();
}
return SingletonInstan ce;
}
};
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<OpenG LRenderer>;
}
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::AbstractM anager<Concrete Manager> * Mgr =
Core::ConcreteM anager::Instanc e();
Mgr->MethodDeclared InAbstractManag er();
The compiler complains with :
unresolved external symbol "public: void __thiscall
AbstractManager <class
ConcreteManager >::MethodDeclar edInAbstractMan ager()"
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