以下代码段
#include "uWS/uWS.h"
int main()
{
uWS::Hub h;
h.onConnection([&h](uWS::WebSocket<uWS::SERVER> *ws, uWS::HttpRequest req) {
std::cout << "Connected!!!" << std::endl;
});
h.run();
}
生成错误
Severity Code Description Project File Line Suppression State Error (active) E0304 no instance of overloaded function "uWS::Hub::onConnection" matches the argument list pid c:\Users\R\src\main.cpp 6 Error C2664 'void uWS::Group<false>::onConnection(std::function<void (uWS::WebSocket<false>,uWS::HttpRequest)>)': cannot convert argument 1 from 'main::<lambda_1afdd040d2f03ded23f0c636dc85475d>' to 'std::function<void (uWS::WebSocket<true>,uWS::HttpRequest)>' pid c:\users\r\src\main.cpp 8
使用Windows SDK版本10.0.15063.0在Visual Studio 2017 IDE中构建时, 其中“uWS / uWS.h”包含tiny web sockets definitions
可能是什么问题?
答案 0 :(得分:1)
从错误消息看,onConnection
函数看起来需要一个uws::WebSocket
的函数,但是你的lambda函数接受uws::WebSocket*
。