#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;
}
本文展示了一个使用C++11标准库中的线程功能的示例代码。通过静态成员函数启动线程,并调用类实例的成员函数来打印消息。此代码片段演示了如何在C++中创建和管理线程。
1463

被折叠的 条评论
为什么被折叠?



