Hi,
I have a class A with a static pointer to some data. The pointer is static
because I want to access the data from all instances of the class. The data
itself is allocated when the first instance of A is constructed:
# a.h
class A
{
private:
static char* sm_data;
public:
A();
};
# a.cpp
A::A()
{
if (sm_data == NULL)
sm_data = new char[1024];
}
char* A::sm_data = NULL;
This works fine, but what should I do to make sure that sm_data is
deallocated when I close the application? I could always use reference
counting and delete [] sm_data when the last instance of A is deleted, but
that is a little cumbersome. I could also have a static function that is
called from the application's main class when it exits, but then I'd have to
rely on other parts of the application.
My question is: how would you solve this?
Regards,
Jahn Otto