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

12,055

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.

Share:
12,055

Related videos on Youtube

Mihai
Author by

Mihai

loading...

Updated on June 26, 2022

Comments

  • Mihai
    Mihai 6 months

    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?

    • rafix07
      rafix07 over 3 years
      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.

Related