简体   繁体   中英

error: static assertion failed: std::thread arguments must be invocable after conversion to rvalues

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;
}

Why is this not working?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM