Problem with Singleton template (2)
Hi
Further to my previous post (which hasn't passed the moderator yet) I
have a
problem with a template Singleton class. My goal is to derive a list
template from my Singleton template, and then to derive various types
of list
from the list template. My problem is that the compiler complains that
the
derived list class cannot see the Singleton's instance method.
Here is a very cut down presentation of my code (with the finer points
of the
Singleton missing for clarity):
template <typename T> class Singleton
{
public:
static T* instance()
{
if (mp_instance == 0) // First time call?
mp_instance = new T; // Yes: create sole instance
return mp_instance;
}
etc.
}
template <class T> class MyList : public Singleton< MyList<T> >
{
friend class Singleton<MyList>;
private:
MyList() {};
~MyList() {};
etc.
}
class IntList : public MyList<int>
{
};
I try to get a pointer to IntList:
IntList* pIntList = IntList::mp_instance();
This line fails with compiler error:
error: member "Singleton<T>::mp_instance [with T=MyList<int>]" is
inaccessible
Please can anyone suggest how to fix this?
BR
David
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]