Boost logo

Boost :

From: Jeff Garland (jeff_at_[hidden])
Date: 2007-04-05 09:54:40


Kevin Yuan wrote:
>> 2007/4/4, Martin Bonner <Martin.Bonner_at_[hidden]>:
>> Static variable in an inline function.
>>
>
> Yes, I agree. Something like:
>
> // st.h
> class st
> {
> private:
> st(){}
> public:
> static st* get_instance()
> {
> static st* inst = new st;
> return inst;
> }
> };
>

Yeah sure, classic Meyer's singleton. Couple problems. It's not thread safe
and you could easily inline this code into multiple translation units. In
both cases you might wind up with multiple copies of your singleton in the
process. It's this sort of thing that makes true singletons devilishly hard
to do...

Jeff


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