Consider the following code:
class A
{
....
shared_ptr<std::thread> mThread;
void Step();
void LaunchTrhead();
}
void A::LaunchThread()
{
...
mThread=make_shared<std::thread>(Step); // This line gives an error
...
}
void A::Step()
{
...
}
我试图初始化共享指针mThread,使其调用函数Step。 然而,编译器给出错误“invalid initialization of reference of type ... from expression of type 'unresolved overloaded function type'”。 很明显我做了一些愚蠢的事情,但我想不出来是什么问题。 有人能帮忙吗? 提前致谢!
std::thread
构造函数(以及std::bind
和std::async
):mThread = std::make_shared<std::thread>(&A::Step, this);
- Caseythread
的构造函数(或上面示例中的make_shared
)。 - Praetorian