//定义线程指针
std::unique_ptr<std::thread> thread_;
//指向定义函数
threadCapture_.reset(new std::thread([this]()
{
func();
}
));
#功能函数
void func()
{
while(1)
{
std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
//compute
std::chrono::system_clock::time_point expectedNext = now + std::chrono::milliseconds((int)(1000.0f / 30));
std::this_thread::sleep_until(expectedNext);
}
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
2.智能指针使用:
class class2: public class1
std::shared_ptr<class1> p1;
p1.reset(new class2);