全部博文(46)
分类: C/C++
2012-06-13 21:37:55
#pragma once
class Singleton
{
public:
virtual ~Singleton(){}
static Singleton* GetInstance(int num);
void mysingle()
{
cout<<"my data\t"<
protected:
Singleton(int num)
{
m_inum = num;
}
private:
int m_inum;
static Singleton* m_single;
};
Singleton* Singleton::m_single = NULL;
Singleton* Singleton::GetInstance(int num)
{
if (m_single == NULL)
{
m_single = new Singleton(num);
}
return m_single;
}
/****************************************************************/
#include
using namespace std;
Singleton* single1 = Singleton::GetInstance(10);
single1->mysingle();
Singleton* single = Singleton::GetInstance(5);
single->mysingle();