Singleton implementation
Zack Rusin
zack at kde.org
Wed Jul 9 17:04:24 BST 2003
On Wednesday 09 July 2003 03: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.
You have to make your class a friend of the construction/destruction
policy you have chosen for your singleton. So if you want to
construct/destruct it with new/delete you put a friend declaration like
the following in your class:
class YourClass{
...
friend struct CreateUsingNew<YourClass>;
...
};
Zack
--
For every complex problem there is an answer that is clear, simple, and
wrong.
-- H L Mencken
More information about the kde-core-devel
mailing list