C++分析研究  
C++
日历
<2011年3月>
272812345
6789101112
13141516171819
20212223242526
272829303112
3456789
统计
  • 随笔 - 92
  • 文章 - 4
  • 评论 - 4
  • 引用 - 0

导航

常用链接

留言簿

随笔档案

文章档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜

 

  #include

  #include

  class CA

  {

  public:

  inline static CA *GetInstance(void)

  { www.liuhebao.com

  assert(m_instance != NULL);

  return m_instance;

  }

  void Print(void)

  {

  puts("主类的Print函数运行看看");

  }

  class Garbage//用来分配内存的嵌套类

  { www.yzyedu.com

  public:

  Garbage(int i, int j)

  {

  printf("Garbage分配内存开始:%d %d\n", i, j);

  m_instance = new CA(123123, 234234234);

  }

  ~Garbage()

  {

  delete m_instance;

  puts("Garbage收拾残局结束");

  }

  };

  static Garbage m_garbage;

  protected: www.yzjxsp.com

  friend class Garbage;

  CA(int i, int j){printf("主类构造函数运行: %d %d\n", i, j);}

  ~CA(){printf("主类析构函数运行,结束了哦\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;

  }

posted on 2011-03-21 00:44 HAOSOLA 阅读(223) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


 
Copyright © HAOSOLA Powered by: 博客园 模板提供:沪江博客
PK10开奖 PK10开奖