Singleton implementation

Cornelius Schumacher schumacher at
Wed Jul 9 09:02:29 BST 2003

On Wednesday 09 July 2003 09:46, Bo Thorsen wrote:
> On Wednesday 09 July 2003 09:32, Cornelius Schumacher wrote:
> > On Wednesday 09 July 2003 07:11, Zack Rusin wrote:
> > > I had this on the drive for quite a while - it's a singleton
> > > implementation heavily based on the one from "Modern C++ Design".
> >
> > How do I make a singleton with a private constructor with your class?
> > It's often desirable to prevent a singleton from being used without the
> > singleton semantics.
> friend class KSingleton;

Sorry? There is no class KSingleton in Zacks code.

> Also, remember to make the destructor private. It's a common failure of
> singletons to forget this, and if a piece of code ever does
> delete theInstance;
> your app dies.

This depends. If the singleton is written in a way that it is correctly shut 
down on deletion and is reinstantiated when calling the instance() function 
again, it can make sense to have a public destructor.

Cornelius Schumacher <schumacher at>

More information about the kde-core-devel mailing list