您的位置:首页 > 其它

简单的单例实现

2014-03-17 09:36 381 查看
//////test.h

class test
{
public:
~test(void);
static test* GetInstance();
int Geta();
private:
static test m_instance;
test(void);
int a;
};


//////test.cpp

test::test( void )
{
a = 10;
printf("create test!\n");
}

test::~test( void )
{
printf("destroy test!\n");
}

test* test::GetInstance()
{
return &m_instance;
}

int test::Geta()
{
return a;
}

test test::m_instance;


void main()
{

printf("test a:%d\n",test::GetInstance()->Geta());
getchar();

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: