Subject: Re: [boost] [Boost.utility]
From: Andrew Chinkoff (achinkoff_at_[hidden])
Date: 2010-01-26 10:00:58
> I've always been mystified as to why a singleton instance is accessed
> via pointer rather than by reference.
I think that reference access is more reliable than pointer one because
references are only aliases but pointers are actual 4 (or 8) bytes objects.
Aliases can not be copied but pointers do.
> Singleton models a one-and-only-one relationship a pointer models a
> relationship. That said, in my experience singletons are generally used
> as a crutch to access global state.
I think that the best way to solve the problem - increase the level of
indirection, don't I? Explanation for this should be further.
"One-and-only-one" instance is incapsulated inside Singleton class.
Singleton class controls access to the instance. How this access is
controlled - that is a personal matter of programmer and the task been
solving. Global objects are naked instances. For me "global" means
"dangerous" but "Singleton" means "flexible" and "safe".
-- View this message in context: http://old.nabble.com/-Boost.utility--tp27309940p27323937.html Sent from the Boost - Dev mailing list archive at Nabble.com.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk