在课堂上引用功能时“没有匹配的呼叫功能”

时间:2017-11-20 12:33:10

标签: c++ websocket arduino arduino-esp8266

我正在尝试使用Scheduler来使用ESP8266 WebSocketsServer实例,但我无法使用onEvent函数进行编译。在设置中,我正在调用

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

WebServer是类,webSocketEvent定义为

void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) {...}

这是完整的编译错误日志:

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)>}'

你知道我做错了什么吗?

1 个答案:

答案 0 :(得分:1)

需要明确告诉

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

要解决此问题,需要从

更改呼叫
webSocket.onEvent(std::bind(&WebServer::webSocketEvent, this));

webSocket.onEvent(std::bind(&WebServer::webSocketEvent, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));