It will have static lifetime and be destroyed after
main
returns:
static std::auto_ptr<T> thePointer;
Another option is to register your own atexit
function:
// static
void YourClass::freePointer(void)
{
delete getPointer();
}
// static
T* YourClass::getPointer(void)
{
if (!thePointer)
{
thePointer = new T;
atexit(freePointer);
}
return thePointer;
}
Which will have the same effect.
http://stackoverflow.com/questions/2429408/c-freeing-static-variables