在类中引用函数时的"No Matching Function for Call"
"No Matching Function for Call" when referencing function in class
我正在尝试使ESP8266 WebSocketServer实例与调度程序一起使用,但是我无法通过一个vent函数进行编译。在设置中,我正在调用
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:
...ArduinolibrariesWebSocketssrc/WebSocketsServer.h:58:14: note: void WebSocketsServer::onEvent(WebSocketsServer::WebSocketServerEvent)
void onEvent(WebSocketServerEvent cbEvent);
^
...ArduinolibrariesWebSocketssrc/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)>}'
您知道我在做什么错吗?
std::bind()
需要明确告知从辅助手机的辅助手术到原始函数时的参数。根据功能中的参数数量,可能需要或多或少的占位符。
要解决此问题,需要从
更改呼叫webSocket.onEvent(std::bind(&WebServer::webSocketEvent, this));
to
webSocket.onEvent(std::bind(&WebServer::webSocketEvent, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
相关文章:
- "error: no matching function for call to"构造函数错误
- 调用专用模板时出错"no matching function for call to [...]"
- "no matching function for call to 'Vector::Vector'"错误
- 我在 ifstream input_file(文件名)行中收到错误"no matching function to call";
- 为什么当我在 std::string 中打开文件名的 fstream 时出现"no matching function"错误?
- 从 TVector2 类派生复杂类:"No matching function for call to Complex::Complex()"
- 学习 c++,编译错误"no matching function for call"
- C++ "error: no matching function"
- 尝试实例化模板类的对象时出现"No Matching Constructor"错误
- 结构错误:"no matching function for call to "
- 创建函数变体向量时"No matching function for call"错误
- 为什么"std::isdigit"在 Windows 上报告C++"no matching overloaded function"
- 编译时二叉搜索树错误的反向迭代器表示"no matching function call for operator=()"
- 如果子类中没有构造函数方法,则错误"no matching function for call to 'LGame::LGame(String&)'"
- 提升多精度浮点数128:标准::exp错误:'no matching function for call'
- "error: no matching function for call to",我无法更改结构的定义
- 替换派生对象向量中的对象"no matching function to call"
- 我的程序显示许多错误,"error: no matching function for call to 'getPercentScore'"
- 为什么即使我定义了它们"no matching overload found"也会出现错误
- 为什么有一个指向此代码行(第 7 行)的"no matching call for function"错误?