【问题标题】:error: static assertion failed: std::thread arguments must be invocable after conversion to rvalues错误:静态断言失败:std::thread 参数在转换为右值后必须是可调用的
【发布时间】: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


【解决方案1】:

调用thread ctor时缺少初始整数值:thread(std::ref(tfunc), 123)。

线程体函数取整数,需要在线程启动时提供。

【讨论】:

    猜你喜欢
    • 2021-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-18
    • 2020-02-01
    • 1970-01-01
    • 2018-01-30
    • 1970-01-01
    相关资源
    最近更新 更多