Listing 2
...
class Log {
public:
Log() { echo("Log c'tor"); }
~Log() { echo("Log d'tor"); }
void echo(const char *s) { cout << s << endl; }
};
typedef SingletonHolder<
Log, CreateUsingNew, PhoenixSingleton
> log;
class Example {
public:
Example() { echo("Example c'tor"); }
~Example() {
echo("Example d'tor starting");
log::Instance().echo("Log: inside Example d'tor");
echo("Example d'tor finished");
}
void echo(const char *s) { cout << s << endl; }
};
int main(int argc, char* argv[])
{
Example *example = new Example();
SetLongevity(
example, 1, &Loki::Private::Deleter<Example>::Delete
);
log::Instance().echo("Log now instantiated.");
return 0;
}