重写代码 c++ 时未解析的重载函数类型
Unresolved overloaded function type when rewriting code c++
我在 nodeMCU 上运行的项目中使用了 ESP8266WiFiMesh 库。当库提供的示例在 Ardunino ino 文件中时,它运行良好,但是当我将其重写为 c ++ cpp h 文件时,我遇到了一些问题。在 Mesh::Mesh 中创建 ESP8266WiFiMesh 类的实例时,我提供了两个参数:chipId 和回调。
提供回调函数(管理请求(时出现的错误
<unresolved overloaded function type> to std::function<String(String)>
我挣扎了几天,找不到任何解决方案。
这是我使用的原始示例代码。 https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFiMesh/examples/HelloMesh/HelloMesh.ino
目数.cpp :
#include "Mesh.h"
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMesh.h>
unsigned int request_i = 0;
unsigned int response_i = 0;
Mesh::Mesh() {
/* Create the mesh node object */
/* Here I'm getting Unresolved overloaded function when providing manageRequest function (callback) */
ESP8266WiFiMesh mesh_node = ESP8266WiFiMesh(ESP.getChipId(), manageRequest);
/* Create the utils node object */
utilsy = new Utils();
#ifdef DEBUG
Serial.println("Setting up mesh node...");
#endif
/* Initialize the mesh node */
mesh_node.begin();
}
/**
* Callback for when other nodes send you data
*
* @request The string received from another node in the mesh
* @response The string to send back to the other node
*/
String Mesh::manageRequest(String request) {
/* Split request */
String requestedTo = utilsy->getDelimitedValues(request, '.', 0);
String requestedFrom = utilsy->getDelimitedValues(request, '.', 1);
const char *cstr = requestedFrom.c_str();
String requestedMessage = utilsy->getDelimitedValues(request, '.', 2);
String requestedState = utilsy->getDelimitedValues(request, '.', 3);
#ifdef DEBUG
/* Print out received message */
Serial.print("Requested from: " + requestedFrom);
Serial.print("tMessage: " + requestedMessage);
Serial.println("tRequested state: " + requestedState);
#endif
/* return a string to send back */
char response[60];
//TODO should send back with same message and giving proper state [0,1] whether LED turned on/off
sprintf(response, "%s.%d.%d.%d", cstr, ESP.getChipId(), response_i++, 1);
return response;
}
代码不起作用,因为您的函数是一个类方法,但您可以使用 std::bind 来获得适当的结果:
ESP8266WiFiMesh mesh_node = ESP8266WiFiMesh(
ESP.getChipId(),
std::bind(&Mesh::manageRequest, this, std::placeholders::_1));
相关文章:
- 为什么这个运算符<重载函数对 STL 算法不可见?
- 可以打印矢量和矢量中的矢量的非重载C++函数
- 错误 没有与参数列表匹配的重载函数"getline"实例
- 使用模板重载函数
- C++线程中,没有重载函数接受 X 参数
- std::vector 没有重载函数的实例与参数列表匹配
- C++重载函数,一个采用基类的参数,另一个采用派生类的参数
- 错误:无法解析对重载函数的引用;你的意思是调用它吗?
- 对重载函数find_first_not_of的不明确调用
- 如何从重载解析中删除重载函数?
- CUDA:重载函数"isnan"的多个实例
- C++派生类重载函数(带有 std::function 参数)不可见
- 避免在人为的重载函数调用中拼写出类型
- C++:如何为多个重载函数保留通用代码路径?
- 什么时候可以使用常量装饰调用我的重载函数?
- 尝试使用谓词函数会导致错误:"std::sort"未找到匹配的重载函数
- std::调用,未找到匹配的重载函数
- 为什么在传递长整型时调用具有两个双精度类型的参数的重载函数?
- 为什么使用不匹配的参数调用重载函数仍然有效
- 如何通过签名作为模板参数来解决重载函数?