Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 994
Mihai Avatar asked Jul 31 '19 13:07

Mihai


1 Answers

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.

like image 66
Mihai Avatar answered Nov 15 '22 14:11

Mihai