Your suggestion is good and all, however it doesn't really give me much
benefit. If I'm going to go through the trouble to do that, I might as well
go ahead and just not use the singleton object you have. The reason why I'm
looking for a base class to derive from is so that I don't explicitly have
to re-write the same singleton implementation details for every class,
listed below:
- Generic public static "Instance()" function
- Generic public static "Release()" method (if your singleton instance is on
the heap. Stack instances do not require this)
- Declaration/definition of the actual singleton static variable
- Preventing the singleton class from being instantiated (this means the
base class needs to somehow prevent the derived class from being
instantiated outside of itself).
If I can find a class that automates this for me JUST by deriving from it,
that would be perfect. However this may be too much to ask? Your singleton
idea is great, however it doesn't exactly fulfill what I'm looking for. I
apologize for not having elaborated on this thoroughly to begin with.
On Dec 5, 2007 3:53 PM, Sohail Somani
On Wed, 05 Dec 2007 15:35:35 -0600, Robert Dailey wrote:
How do you prevent people from instantiating Object (in your example)?
Also, I was more or less looking for a member-specific way of doing the singleton access. For example:
Object::instance()
You can do something like:
struct Object { friend class singleton<Object>; Object& instance() { return singleton<Object>::instance(); }
private: Object(); ~Object(); };
I'm sure there is a nicer way to wrap that up.
-- Sohail Somani http://uint32t.blogspot.com
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users