
5 Apr
2007
5 Apr
'07
1:54 p.m.
Kevin Yuan wrote:
2007/4/4, Martin Bonner <Martin.Bonner@pi-shurlok.com>: 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