以 this 为例从 cppreference 的 packaged_task
描述中,出现一个名为 task
的类。它是什么?
#include <iostream>
#include <future>
#include <thread>
int main()
{
std::packaged_task<int()> task([](){return 7;}); // wrap the function
std::future<int> result = task.get_future(); // get a future
std::thread(std::move(task)).detach(); // launch on a thread
std::cout << "Waiting...";
result.wait();
std::cout << "Done!\nResult is " << result.get() << '\n';
}
最佳答案
task
是 std::packaged_task<int()>
类型的对象。它是在第一行创建的。
关于c++ - 此示例中 cppreference 中的任务是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12221136/