Hello, recently I had to start developing a multi-threaded application (for the first time) and came across such a problem: I need to create a thread for a specific object with the transfer of a non-static function to the designer, Google did not give anything worthwhile.
- Tell me, is it even possible?
- If not, how is it treated?
In the abstraction: there is a System class, it has a non-static private update() method that I have to monitor by initializing the private thread* Thread pointer in the class constructor.
PS the update method calls the move(...) , which is tied to the object, that is, I cannot make the update static without creating a container that stores all user data, and this is expensive
#include <thread> //еще включения ... class System { //некоторые поля и методы... //... thread* Thread; static thread* sThread; System() { Thread = new thread(update);//ошибка! отсутствуют экземпляры констуктора соответствующий ... для std::thread::thread (void()) } void update() { //... move(...); //... } void move() { //работает с полями объекта } }; { //где-то создается System* system = System; } PS (2) Climbed with c #, there you can initialize threads with non-static methods (sort of), do not judge strictly