mercredi 11 janvier 2023

How to pass a member function to a member thread in c++? [duplicate]

I am trying to make a thread that is inside of a class, and the function that the thread is supposed to execute is also inside of the class. I will present the example, and then the associated compiler error:

#include <thread>

class name
{
    public:
    
        void func1(){}
    
        void func2()
        {
            std::thread t(func1);
        }
};

int main(){}

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

I tried a combination of the helpers within the header.

Aucun commentaire:

Enregistrer un commentaire