#include <iostream>
#include <windows.h>
#include<thread>
using namespace std;
class sig
{
private:
sig() {
cout << "构造函数start" << endl;
Sleep(1000);
cout << "构造函数end";
};
sig(sig &) = delete;//sig(sig &) {};
public:
static sig& getSig() {
static sig a;
std::cout << &a << "\n";
return a;
}
};
int main()
{
{
std::thread threads[10];
for (int i = 0; i <10; ++i)
{
Sleep(1000);
threads[i] = std::thread([]() {sig &b = sig::getSig(); std::cout << &b << endl; b.~sig(); });
}
for (auto &i : threads)
{
i.join();
}
}
cout << "OK" << endl;
//sig &b = sig::getSig();
return 0;
}
C++11单例模式
最新推荐文章于 2023-03-14 15:34:21 发布