c++11单例模式创建线程

​
#include<thread>
#include<iostream>

using namespace std;

class Test{
public:
    void say(){
        cout<< "hello c++11" <<endl;
    }

    static void startThread(){
        thread th(bind(&Test::say,Test::Instance()));
        th.join();
    }
    static Test* Instance(){
        static Test t;
        return &t;
    }
protected:
    Test(){}
};

int main()
{
    Test::startThread();

    return 0;
}

​
发布了133 篇原创文章 · 获赞 175 · 访问量 15万+

猜你喜欢

转载自blog.csdn.net/c_shell_python/article/details/102543458