有人能告诉我怎样才能运行一个新的线程与成员函数从不同类的对象作为这个类的成员函数?什么即时尝试做我仍然得到错误。从另一个类的成员函数的类中的线程
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();
}
'while(1){}'是UB,参见例如[is-this-infinite-recursion-ub](https://stackoverflow.com/questions/5905155/is-this-infinite-recursion- UB)。 – Jarod42