
26 Jan
2010
26 Jan
'10
9:41 p.m.
I've always been mystified as to why a singleton instance is accessed via pointer rather than by reference. Singleton models a one-and-only-one relationship a pointer models a zero-or-one relationship. That said, in my experience singletons are generally used as a crutch to access global state. I use them in a game to access part of the global state from a different
Jeff Flinn wrote: part. For example, the part that does random numbers keeps state, and for various reasons, given a particular seed must be deterministic, so there can be only one. It's single threaded though. I store an instance as a pointer, but return it from the singlecrutch <grin;> as reference. Patrick