By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,720 Members | 2,145 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,720 IT Pros & Developers. It's quick & easy.

Singleton class

P: n/a
hi,

Hope i get some answers.

What is single ton class?how to make singleton class?use of single ton
class.

Regards

Naveen

Dec 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
md
when we create a class with constructor in private, then the class is
singleton class.
Purpose is when u don't want any body to create a object of ur class
then place constructor in private.

Dec 21 '05 #3

P: n/a

md escreveu:
when we create a class with constructor in private, then the class is
singleton class.
Purpose is when u don't want any body to create a object of ur class
then place constructor in private.


Note quite. A singleton is a class that allows only one instance to be
created. A singleton must have private constructors and destructor in
order to disallow arbitrary creation objects, but the fact that a class
has private constructors and destructors doesn't guarantee that it is a
singleton:

class nosingleton
{
public:
//may leak
nosingleton * create() { new nosingleton; }
private:
nosingleton() {}
nosingleton(const nosingleton &); //not implemented
nosingleton & operator = (const nosinlgeton &); //not implemented
};

Each time you call create() you get a new object of type nosingleton.
And, in addition, if you define the destructor of nosingleton private,
you definitely will have memory leaks.

HTH,

Marcelo Pinto

Dec 21 '05 #4

P: n/a
If possible plz explain with one example

Dec 21 '05 #5

P: n/a
sa**************@wipro.com wrote:
If possible plz explain with one example


Please quote the message you are responding to.

See the FAQ for an example:

http://www.parashift.com/c++-faq-lit....html#faq-20.8

Cheers! --M

Dec 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.