C++ &引用;“调用”没有匹配的函数;在类中引用函数时

C++ &引用;“调用”没有匹配的函数;在类中引用函数时,c++,websocket,arduino,arduino-esp8266,C++,Websocket,Arduino,Arduino Esp8266,我试图让一个ESP8266 WebSocketsServer实例与一个调度程序一起工作,但我无法让它使用OneEvent函数进行编译。在设置中,我正在呼叫 webSocket.onEvent(std::bind(&WebServer::webSocketEvent,this)) WebServer是类,而webSocketEvent定义为 void webSocketEvent(uint8\u t num、WStype\u t type、uint8\u t*有效负载、大小\u t长度){…} 以

我试图让一个ESP8266 WebSocketsServer实例与一个调度程序一起工作,但我无法让它使用OneEvent函数进行编译。在设置中,我正在呼叫

webSocket.onEvent(std::bind(&WebServer::webSocketEvent,this))

WebServer
是类,而
webSocketEvent
定义为

void webSocketEvent(uint8\u t num、WStype\u t type、uint8\u t*有效负载、大小\u t长度){…}

以下是完整的编译错误日志:

sketch_nov20a.ino: In member function 'virtual void WebServer::setup()':

sketch_nov20a:25: error: no matching function for call to 'WebSocketsServer::onEvent(std::_Bind_helper<false, void (WebServer::*)(unsigned char, WStype_t, unsigned char*, unsigned int), WebServer* const>::type)'

       webSocket.onEvent(std::bind(&WebServer::webSocketEvent, this));

                                                                    ^

sketch_nov20a.ino:25:68: note: candidate is:

In file included from sketch_nov20a.ino:3:0:

...\Arduino\libraries\WebSockets\src/WebSocketsServer.h:58:14: note: void WebSocketsServer::onEvent(WebSocketsServer::WebSocketServerEvent)

         void onEvent(WebSocketServerEvent cbEvent);

              ^

...\Arduino\libraries\WebSockets\src/WebSocketsServer.h:58:14: note:   no known conversion for argument 1 from 'std::_Bind_helper<false, void (WebServer::*)(unsigned char, WStype_t, unsigned char*, unsigned int), WebServer* const>::type {aka std::_Bind<std::_Mem_fn<void (WebServer::*)(unsigned char, WStype_t, unsigned char*, unsigned int)>(WebServer*)>}' to 'WebSocketsServer::WebSocketServerEvent {aka std::function<void(unsigned char, WStype_t, unsigned char*, unsigned int)>}'
sketch\u nov20a.ino:在成员函数“virtual void WebServer::setup()”中:
草图\u nov20a:25:错误:调用“WebSocketsServer::OneEvent(std::\u Bind\u helper::type)”时没有匹配的函数
onEvent(std::bind(&WebServer::webSocketEvent,this));
^
草图编号:20a.ino:25:68:注:候选人为:
包含在草图\u nov20a.ino:3:0中的文件中:
…\Arduino\libraries\WebSockets\src/WebSocketsServer.h:58:14:注意:void WebSocketsServer::onEvent(WebSocketsServer::WebSocketServerEvent)
void onEvent(WebSocketServerEvent cbEvent);
^
…\Arduino\libraries\WebSockets\src/WebSocketsServer.h:58:14:注意:参数1没有从'std:_Bind_helper::type{aka std::_Bind}'到'WebSocketsServer::WebSocketServerEvent{aka std::function}的已知转换
你知道我做错了什么吗?

std::bind()
需要明确告知将其helper调用时的参数传递给原始函数。根据函数中参数的数量,可能需要更多或更少的占位符

要解决此问题,需要将呼叫从

webSocket.onEvent(std::bind(&WebServer::webSocketEvent, this));

std::bind()
需要明确告知将其助手调用到原始函数时的参数传递给原始函数。根据函数中参数的数量,可能需要更多或更少的占位符

要解决此问题,需要将呼叫从

webSocket.onEvent(std::bind(&WebServer::webSocketEvent, this));


好心点,发一封信。似乎
onEvent
不接受
std::bind
的结果,但是如果没有看到相关的代码,就很难知道。尝试构造std::函数并传递它。。。?std::function func=std::bind(…);webSocket.onEvent(func);隐式转换应该可以工作,但可能显式构造在错误消息中为您提供了一些额外的信息。请发一封邮件。似乎
onEvent
不接受
std::bind
的结果,但是如果没有看到相关的代码,就很难知道。尝试构造std::函数并传递它。。。?std::function func=std::bind(…);webSocket.onEvent(func);隐式转换应该可以工作,但可能显式构造在错误消息中为您提供了一些额外的信息。