c++实例研究

从0开始

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  104 随笔 :: 0 文章 :: 20 评论 :: 0 Trackbacks
#include <iostream>
#include 
<cstdlib>
using namespace std;

int& use_count()
{
    
static int uc = 0;
    
return uc;
}


int main()
{
    cout
<<++use_count()<<endl;
    cout
<<++use_count()<<endl;
    cout
<<++use_count()<<endl;
    system(
"PAUSE");
    
return 0;
}
posted on 2010-05-04 09:08 elprup 阅读(209) 评论(1)  编辑 收藏 引用

评论

# re: 全局变量首次运行时初始化的包装 2010-05-04 09:25 战魂小筑
其实这就是静态对象版本的singleton实现原理,是个很好的方法,避免CRT的初始化问题  回复  更多评论
  


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