Re: Private constructor
From: Matej Pivoluska (spam_at_spam.com)
Date: 12/14/03
- Next message: P.J. Plauger: "Re: Can anyone sell me VC 4.0 or 5.0?"
- Previous message: Richard Heathfield: "Re: C 99 -- C++ 2003 diffs"
- In reply to: Andy: "Private constructor"
- Next in thread: jeffc: "Re: Private constructor"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 14 Dec 2003 17:10:49 +0100
Andy wrote:
> 1) Is there any use of defining a class with a single constructor
> declared in private scope? I am not asking a about private copy
> constructors to always force pass/return by reference.
>
> 2) Is this in any way used to create singletons. Can someone say how?
If you want to create singletons, you have to declare all your constructors
(and operator=, too) as private.
Then you create a public function that checks if singleton was created
(through some static bool member) and then calls (private) constructor.
Then (if check passed) your function returns refernece (or pointer) on your
singleton and set true flag to static member -- singleton was created.
-- mP http://pivoluska.matfyz.cz/
- Next message: P.J. Plauger: "Re: Can anyone sell me VC 4.0 or 5.0?"
- Previous message: Richard Heathfield: "Re: C 99 -- C++ 2003 diffs"
- In reply to: Andy: "Private constructor"
- Next in thread: jeffc: "Re: Private constructor"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|