#include <iostream>
using namespace std;
class Singleton
{
public:
static Singleton* Instance();
void
setValue(int val) { value = val; }
int
getValue() { return value; }
protected:
Singleton()
{}
private:
static Singleton *_instance;
int
value;
};
Singleton* Singleton::_instance = NULL;
Singleton* Singleton::Instance()
{
if
(_instance == NULL)
{
_instance = new Singleton();
}
return
_instance;
}
void main()
{
Singleton *a = Singleton::Instance();
Singleton *b = Singleton::Instance();
a->setValue(10);
cout <<
b->getValue() <<
endl;
}
using namespace std;
class Singleton
{
public:
protected:
private:
};
Singleton* Singleton::_instance = NULL;
Singleton* Singleton::Instance()
{
}
void main()
{
}