在网上看到Meyers提出的线程安全的单例模式,有点搞不懂其中的原理。
Meyers提出的单例模式的代码:
#include <iostream>
class Singleton
{
public:
~Singleton(){
std::cout<<"destructor called!"<<std::endl;
}
Singleton(const Singleton&)=delete;
Singleton& operator=(const Singleton&)=delete;
static Singleton& get_instance(){
static Singleton instance;
return instance;
}
private: