Re: New Singleton Scheme
{ quoted signature and server banner removed. -mod }
On 31 Ago, 10:55, Gerhard Menzl <clcppm-pos...@this.is.invalid> wrote:
Ema wrote:
To be honest I prefer the old school Singleton plus the Init() method
Snippet--------------------
class Singleton
{
Singleton(const Singleton&);
Singleton& operator=(const Singleton&);
public:
void Init(void) {}
static Singleton& Instance(void)
{
Singleton _s;
return _s;
}
};
int main(int argc, char *argv[])
{
Singleton::Instance().Init();
// now ready for MT use
}
What does Init() achieve which the constructor doesn't?
Simply creates the object in a single thread context (you know if
there are any mutex(es) they get created in a thread safe context).
Cheers,
Ema.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]