Topic: Is it guaranteed that a static Object is crated at startup?
Author: "Marco Siciliano" <msicilia@csksoftware.com>
Date: Thu, 2 May 2002 20:05:39 GMT Raw View
Hi,
i have implemented a singelton pattern using a creator object:
Is this save ? Is it guaranteed, that this creator object is created at the
program startup ?
class FooCreator
{
public:
FooCreator()
{
Foo::instance = new Foo;
}
~Foo()
{
delete Foo::instance;
}
};
static FooCreator creator; // IS THIS OK ??????
class Foo
{
public:
static Foo & instance();
private:
static Foo *instance;
friend class FooCreator;
};
Foo & Foo::instance()
{
return *instance;
}
Greetings,
Marco Siciliano
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]