C++11使用静态方法,而且是线程安全的
class Singleton
{
public:
static Singleton& getInstance()
{
static Singleton intance;
return instance;
}
private:
Singleton() {}
Singleton(Singleton const &)=delete; // 禁止使用拷贝和赋值构造函数,防止copy和赋值发生,以保证是一个singleton
void operator=(Singleton const&)=delete;
};