#include <iostream>
#include <cassert>
class Singleton
{
public:
static Singleton& Instance()
{
static Singleton instance;
return instance;
}
public:
Singleton(const Singleton&) = delete;
Singleton(Singleton&&) = delete;
Singleton& operator=(const Singleton&) = delete;
Singleton& operator=(Singleton&&) = delete;
private:
Singleton() = default;
~Singleton() = default;
};
int main()
{
auto& a = Singleton::Instance();
auto& b = Singleton::Instance();
assert(&a == &b);
return 0;
}
相关文章
- 01-02Fortify Audit Workbench 笔记 Race Condition: Singleton Member Field 竞争条件:单例的成员字段
- 01-02Singleton(Reference:Design Patterns - Elements of Reusable Object-Oriented Software)
- 01-02设计模式3 - 单例模式【Singleton Pattern】
- 01-02.NET设计模式-单件模式(Singleton Pattern)
- 01-02Keep Windows Forms Singleton via Mutex key word
- 01-02剑指 offer set 28 实现 Singleton 模式
- 01-02设计模式(1)--singleton
- 01-02单例(Singleton)
- 01-02单例模式(Singleton Pattern)
- 01-021.5.1. The Singleton Scope (单例作用域)