Nested classes allocate reclaimed memory:
#include <stdio.h>
#include <assert.h>
Class CA
{
Public
inline static CA *getinstance (void)
{
ASSERT (M_instance!= NULL);
return m_instance;
}
void Print (void)
{
Puts ("Check the print function of the main class");
}
Class garbage//nested classes used to allocate memory
{
Public
Garbage (int i, int j)
{
printf ("Garbage allocating memory Start:%d%dn", I, j);
M_instance = new CA (123123, 234234234);
}
~garbage ()
{
Delete m_instance;
Puts ("Garbage clean up the pieces end");
}
};
static garbage m_garbage;
Protected
Friend class Garbage;
CA (int i, int j) {printf ("main class constructor runs:%d%dn", I, j);}
~ca () {printf ("main class destructor running, End oh N");}
Static CA *m_instance;
};
CA *ca::m_instance = NULL;
Ca::garbage Ca::m_garbage (2, 3);
int main ()
{
CA *CMB = Ca::getinstance ();
Cmb->print ();
return 0;
}