错误:静态断言失败:std::thread 参数在转换为右值后必须是可调用的 [英] error: static assertion failed: std::thread arguments must be invocable after conversion to rvalues

查看:798
本文介绍了错误:静态断言失败:std::thread 参数在转换为右值后必须是可调用的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向 std::thread 添加一个 std::function 并且我偶然发现了这个错误

I am trying to add a std::function to std::thread and i stumble upon this error

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(std::ref(tfunc), 123).

The initial integer value is missing when thread ctor is called: thread(std::ref(tfunc), 123).

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

Function of thread body takes integer, you need to provide it when thread starts.

这篇关于错误:静态断言失败:std::thread 参数在转换为右值后必须是可调用的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆