Memory for allocating Nested classes:
# 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 ("run the Print function of the main class ");
}
Class Garbage // nested class used to allocate memory
{
Public:
Garbage (int I, int j)
{
Printf ("Garbage memory allocation start: % d % dn", I, j );
M_instance = new CA (123123,234 234234 );
}
~ Garbage ()
{
Delete m_instance;
Puts ("Garbage completion ");
}
};
Static Garbage m_garbage;
Protected:
Friend class Garbage;
CA (int I, int j) {printf ("Main class constructor run: % d % dn", I, j );}
~ CA () {printf ("Main class destructor running, ended 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;
}