mercredi 30 août 2017

Thread inside a class with member function from another class

Can someone tell me how can I run a new thread with member function from a object of diffrent class as a member function of this class ? What ever im trying to do Im still getting errors.

no match for call to '(std::thread) (void (Boo::*)(), Boo&)'|
no match for call to '(std::thread) (void (Foo::*)(), Foo*)'|

#include <iostream>
#include <thread>
using namespace std;
class Boo
{
public:
    void run()
    {
        while(1){}
    }
};

class Foo
{
public:
    void run()
    {
        t1(&Boo::run,boo);
        t2(&Foo::user,this);
    }
    void user();
    ~Foo(){
        t1.join();
        t2.join();
    }
private:
    std::thread t1;
    std::thread t2;
    Boo boo;
};
int main()
{
    Foo foo;
    foo.run();
}

Aucun commentaire:

Enregistrer un commentaire