Thursday, April 8, 2010

Singleton class, a different way

We all knew that, the below class will give us only one instance of the class.
class Singleton
{
private:
static Singleton* singleton;
private:
Singleton();
public:
static Singleton* getIntsance();
};

Just think that is there any other way to do the same. Yes, we have onother solution for it. See below

class Singleton
{
private:
static Singleton* singleton;
private:
~Singleton();
public:
static Singleton* getIntsance();
};

Destructor is in private scope now.

1 comment:

I Hate IBM said...

I guess copy constructor has to be declared private as well.