首先,很抱歉我的英语不好。
我正在编写一个websocket类,并希望有一个
函数作为参数
在
构造器
但我
忘记
一
":"
上
宣言
的
消息处理程序
方法在
WebsocketClient
类。
编译器一直给我这个错误:
错误:无法将“std::string”{aka“std::__cxx11::basic_string<char>”}转换为“int”。
我很困惑,但终于找到了问题所在。
但是为什么编译器不告诉我它无法解析类型呢?
(我认为这是问题所在,因为语法错误)
这是主要代码:
void ws_msg_handler(std::string &msg_recieved){
std::cout << "ws_msg_handler: " << msg_recieved << std::endl;
}
WebsocketClient wsClient("ws://my.secret.ip.adress:7777", ws_msg_handler);
这是班级:
class WebsocketClient {
private:
void message_handler(std:string &recieved_msg); // <- here is ":" missing
public:
char *uri;
WebsocketClient(char *uri, void (*message_handler)(std::string&)){
this->uri = uri;
this->message_handler = message_handler;
};
void ws_data_receive_handler(esp_websocket_event_data_t *data_recieved){
std::string msg_recieved(data_recieved->data_ptr);
this->message_handler(msg_recieved); // <- here it gives the error: "error: cannot convert 'std::string' {aka 'std::__cxx11::basic_string<char>'} to 'int'"
}
};
我试着在谷歌上搜索,最后问聊天gpt。当我提供最后一条信息时,它能够找出语法错误。