#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("主类的Print函数运行看看");
}
class Garbage//用来分配内存的嵌套类
{
public:
Garbage(int i, int j)
{
printf("Garbage分配内存开始:%d %d
", i, j);
m_instance = new CA(123123, 234234234);
}
~Garbage()
{
delete m_instance;
puts("Garbage收拾残局结束");
}
};
static Garbage m_garbage;
protected:
friend class Garbage;
CA(int i, int j){printf("主类构造函数运行: %d %d
", i, j);}
~CA(){printf("主类析构函数运行
,结束了哦
");}
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;
}