Boost logo

Boost :

From: Dave Handley (dave_at_[hidden])
Date: 2005-01-10 14:15:55


Scott Woods wrote:

<long snip>
>
> Sometimes the type-equals-only-instance is a royal pain?
>
> Cheers,
> Scott
>

My view is that you should keep the singleton as a singleton, but write some
code in the singleton to manage N instances. This way your access to PBX
number 1 would be something like:

PBX::GetInstance().GetPBX( 1 );

and so on. It keeps the design of the singleton clean, but allows the
flexibility of "exactly N" instances of a class.

I have to say that I do like Jason's solution using an int template
parameter on the singleton itself - although that has the weakness that
every single function that uses the PBX would probably need to be
templatised by type - where as a solution like I discuss above means that
you PBX (or Important) class would always have the same type.

Dave


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk