
26 Jan
2010
26 Jan
'10
1:17 p.m.
Andrew Chinkoff wrote:
Perhaps some boost::global<T> utility would be better, but a singleton itself is bad practice, in my opinion. boost::global<T> would merely create a global access point to T:
typedef boost::global<int> global_Int; global_int.get() = 5; // getting the global int
Perhaps you're right. It is a matter of taste. But I like to write "Object::Instance().get()" rather than "global_object.get()".
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. Jeff