#include <memory>
#include <iostream>
using namespace std;
class Singleton
{
public:
static Singleton* GetInstance()
{
if (instacne_.get() == NULL)
{
instacne_ = auto_ptr<Singleton>(new Singleton);
}
return instacne_.get();
}
~Singleton()
{
cout<<"~Singleton ..."<<endl;
}
private:
Singleton(const Singleton& other);
Singleton& operator=(const Singleton& other);
Singleton()
{
cout<<"Singleton ..."<<endl;
}
static auto_ptr<Singleton> instacne_;
};
auto_ptr<Singleton> Singleton::instacne_;
void test()
{
Singleton* s1 = Singleton::GetInstance();
Singleton* s2 = Singleton::GetInstance();
}
int main(void)
{
test();
cout<<"......."<<endl;
return 0;
}
#include <iostream>
using namespace std;
class Singleton
{
public:
static Singleton* GetInstance()
{
if (instacne_.get() == NULL)
{
instacne_ = auto_ptr<Singleton>(new Singleton);
}
return instacne_.get();
}
~Singleton()
{
cout<<"~Singleton ..."<<endl;
}
private:
Singleton(const Singleton& other);
Singleton& operator=(const Singleton& other);
Singleton()
{
cout<<"Singleton ..."<<endl;
}
static auto_ptr<Singleton> instacne_;
};
auto_ptr<Singleton> Singleton::instacne_;
void test()
{
Singleton* s1 = Singleton::GetInstance();
Singleton* s2 = Singleton::GetInstance();
}
int main(void)
{
test();
cout<<"......."<<endl;
return 0;
}