【发布时间】:2019-07-31 13:16:47
【问题描述】:
我正在尝试向 std::thread 添加一个 std::function 并且偶然发现了这个错误
error: static assertion failed: std::thread arguments must be invocable after conversion to rvalues
struct Foo {
explicit Foo(const std::function<void(int)>& tfunc)
: thread(tfunc) { //<----- error points here
thread.join();
}
std::thread thread;
}
为什么这不起作用?
【问题讨论】:
-
你为什么不直接使用
thread(tfunc)? -
@NathanOliver 这是我尝试的第一件事,但错误是一样的
-
调用线程 ctor 时缺少初始整数值:
thread(std::ref(tfunc), 123)。线程体函数取整数,需要在线程启动时提供。 -
@rafix07 当然
标签: c++ linux multithreading std