Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <future>
- #include <mutex>
- static std::once_flag inited;
- class Singleton {
- private:
- static Singleton *instance;
- Singleton(){}
- public:
- static Singleton *getInstance(){
- std::call_once(inited,[](){
- instance=new Singleton();
- });
- return instance;
- }
- };
- Singleton* Singleton::instance=nullptr;
- int main(){
- Singleton* p = Singleton::getInstance();
- Singleton* p2 = Singleton::getInstance();
- bool equal_memory_region = p==p2;
- std::cout << equal_memory_region << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement