Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #8363 > unrolled thread

singleton design

Started byasit <lipun4u@gmail.com>
First post2011-07-31 13:22 -0700
Last post2011-08-01 18:39 +0200
Articles 3 — 3 participants

Back to article view | Back to comp.lang.c++


Contents

  singleton design asit <lipun4u@gmail.com> - 2011-07-31 13:22 -0700
    Re: singleton design Dombo <dombo@disposable.invalid> - 2011-07-31 22:29 +0200
    Re: singleton design Lasse Reichstein Nielsen <lrn.unread@gmail.com> - 2011-08-01 18:39 +0200

#8363 — singleton design

Fromasit <lipun4u@gmail.com>
Date2011-07-31 13:22 -0700
Subjectsingleton design
Message-ID<320ced85-f297-49bd-80a1-4c3f23aee7ba@glegroupsg2000goo.googlegroups.com>
I want to design a singleton class. here the rule is to make the constructor private. That's okey. What about copy constructor and assignment operator. If I make it private, certain things like copying and assigning will lead to compiler error. How can I handle them ??

[toc] | [next] | [standalone]


#8364

FromDombo <dombo@disposable.invalid>
Date2011-07-31 22:29 +0200
Message-ID<4e35bb1c$0$30717$5fc3050@news.tiscali.nl>
In reply to#8363
Op 31-Jul-11 22:22, asit schreef:
> I want to design a singleton class. here the rule is to make the
> constructor private. That's okey. What about copy constructor
> and assignment operator. If I make it private, certain things
> like copying and assigning will lead to compiler error.
> How can I handle them ??

It wouldn't be really a singleton if you could copy it, nor would it 
make sense to support assignment if only one can exist, would it?

[toc] | [prev] | [next] | [standalone]


#8388

FromLasse Reichstein Nielsen <lrn.unread@gmail.com>
Date2011-08-01 18:39 +0200
Message-ID<vcuhjdb6.fsf@gmail.com>
In reply to#8363
asit <lipun4u@gmail.com> writes:

> I want to design a singleton class. 

Ick. Please reconsider.

There is usually no good reason to enforce that there is only one
instance of a class. Modelling-wise it might make sense to only
actually create one instance, but using the singleton (anti-)pattern
tends to bite you if you want to test either the class itself or
classes depending on it.

> here the rule is to make the constructor private. That's okey. What
> about copy constructor and assignment operator. If I make it
> private, certain things like copying and assigning will lead to
> compiler error. How can I handle them ??

If you want to only have one copy, you don't want to have assignment
or copying creating more than one instance. If the object is immutable,
it might not make any difference, but it still prevents it from being
a singleton. 
You should only pass the object around by reference or pointer.

/L
-- 
Lasse Reichstein Holst Nielsen
 DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
  'Faith without judgement merely degrades the spirit divine.'

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c++


csiph-web