Hey all I have recently made a Singleton class directly from a book I recently purchased, Here it is:
Code:
class Singleton
{
public:
static void Create();
static void Destroy();
static Singleton * GetInstance()
{
return s_pInstance;
}
static int GetNum();
protected:
static Singleton* s_pInstance;
//Hidden Constructor
Singleton();
};
// Implementation
Singleton* Singleton::s_pInstance = NULL;
void Singleton::Create()
{
if(!s_pInstance)
s_pInstance = new Singleton;
}
void Singleton::Destroy()
{
delete s_pInstance;
s_pInstance = NULL;
}
However if I inherit from it with another class, I am not able to call any of it's own member functions, because of the Singleton Pointer.
My Book doesn't give much information on it, and I might be able to find a way, but I don't want to make many changes without being sure there isn't a better way.
Does any one have a suggestions?
PS: I'm a pretty new programmed, and I appreciate any help.
I am currently using the Dev C++ Software Compiler. The error message returned is..
Class Singleton has no member function named (Function).