Connecting Tech Pros Worldwide Help | Site Map

Initialisation and cleanup

Anonymous
Guest
 
Posts: n/a
#1: Sep 28 '07
I have a class (classA) that requires initialisation ONCE. It also
provides static methods that depend on various variables etc to have
been correctly initialised.

Some sample code to explain the scenario:

class ClassA
{
public:
~ClassA();
static ClassB * fetchB();
static ClassC * fetchC();

private:
ClassA();
static int dummy ;
};


//Impl
namespace
{
int MyInitStuf(){ return 42 ;} //assume this allocs memory
void Cleanup(); //used to clean up previously allocd mem
};

static int ClassA::dummy = MyInitStuf();


I have two questions re the code above:

1). Is the dummy variable GUARANTEED to have been initialised already if
I call one of the static methods (or are the satic variables first
initialised when an INSTANCE is created ?

2). Supposing that the MyInitStuf() function allocates memory etc, how
can I enforce deallocation of the memory allocated during initialisation
? - i.e. at what point do I call Cleanup() ?
Closed Thread