C++ 使用std::function作为参数通过std::thread调用可调用对象

C++ 使用std::function作为参数通过std::thread调用可调用对象,c++,C++,我试图创建一个对成员函数的异步调用,该函数作为std::function类型参数获取。但是,我得到了以下错误: Error C2672 'std::invoke': no matching overloaded function found Error C2893 Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...) n

我试图创建一个对成员函数的异步调用,该函数作为std::function类型参数获取。但是,我得到了以下错误:

Error   C2672   'std::invoke': no matching overloaded function found
Error   C2893   Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...) noexcept(<expr>)'   

MyObject::dispatcher
a
static
member函数吗?否则,您需要提供一个对象,用
std::thread
调用它:

m_dispatchThread = std::thread(&MyObject::dispatcher, this, pfnMessageHandler);
//                                                    ^^^^
//               The object to call the member function on

成功了。谢谢但是,MyObject::dispatcher不是一个静态成员函数,它是一个私有函数。为什么编译器不自动传递“this”?私有成员函数是否一定是静态的?我很困惑。它怎么知道要在哪个对象上执行该方法?C++是关于显式的。
MyObject object;
object.recv(clientMessageHandler);
m_dispatchThread = std::thread(&MyObject::dispatcher, this, pfnMessageHandler);
//                                                    ^^^^
//               The object to call the member function on