This code should be enough for restricting only one instance of singleton class. How can we make two instances of this object?
class Singleton
{
private:
Singleton()
{}
~Singleton()
{}
static Singleton * ptr;
public:
static Singleton * CreateObject()
{
if (!ptr)
ptr = new Singleton;
return ptr;
}
static void freeObject()
{
if (ptr)
{
delete ptr;
ptr = 0;
}
}
};
Singleton * Singleton::ptr = 0;