gpt4 book ai didi

c++ - echo 示例编译错误 :ambiguous call to overloaded function

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:45:16 24 4
gpt4 key购买 nike

我在一些名为 uWebSockets 的开源库中有这些功能我尝试使用 Visual Studio 2013 运行其简单示例的任何方式。

我尝试调用的函数如下所示:

template <bool isServer>
void Group<isServer>::onMessage(std::function<void (WebSocket<isServer>, char *, size_t, OpCode)> handler) {
messageHandler = handler;
}

这个例子是这样的:

int main()
{
uWS::Hub h;


h.onMessage([](uWS::WebSocket<uWS::SERVER> ws, char *message, size_t length, uWS::OpCode opCode) {
ws.send(message, length, opCode);
});

h.listen(3000);
h.run();
}

我得到的错误看起来像这样:

1>D:\dev\cpp\server\uWebSockets\git\uWebSockets\uWebSockets\examples\echo.cpp(9): error C2668: 'uWS::Group<false>::onMessage' : ambiguous call to overloaded function
1> d:\dev\cpp\server\uwebsockets\git\uwebsockets\uwebsockets\src\Group.h(69): could be 'void uWS::Group<false>::onMessage(std::function<void (uWS::WebSocket<false>,char *,size_t,uWS::OpCode)>)'
1> d:\dev\cpp\server\uwebsockets\git\uwebsockets\uwebsockets\src\Group.h(69): or 'void uWS::Group<true>::onMessage(std::function<void (uWS::WebSocket<true>,char *,size_t,uWS::OpCode)>)'
1> while trying to match the argument list '(main::<lambda_f789fc974d6d87c4a2444e6ded66c2a0>)'

问题:
不把Visual Studio升级到2015能解决这个问题吗?
还是与编译器版本无关?

更新:如果我将它设置为:h.onMessage<true>h.onMessage<uWS::SERVER>
我越来越 :这个错误:

1>D:\dev\cpp\server\uWebSockets\git\uWebSockets\uWebSockets\examples\echo.cpp(10): error C2678: binary '>' : no operator found which takes a left-hand operand of type 'bool' (or there is no acceptable conversion)
1> could be 'built-in C++ operator>(void (__cdecl *)(uWS::WebSocket<true>,char *,size_t,uWS::OpCode), void (__cdecl *)(uWS::WebSocket<true>,char *,size_t,uWS::OpCode))'
1> or 'built-in C++ operator>(void (__stdcall *)(uWS::WebSocket<true>,char *,size_t,uWS::OpCode), void (__stdcall *)(uWS::WebSocket<true>,char *,size_t,uWS::OpCode))'
1> or 'built-in C++ operator>(void (__fastcall *)(uWS::WebSocket<true>,char *,size_t,uWS::OpCode), void (__fastcall *)(uWS::WebSocket<true>,char *,size_t,uWS::OpCode))'
1> or 'built-in C++ operator>(void (__vectorcall *)(uWS::WebSocket<true>,char *,size_t,uWS::OpCode), void (__vectorcall *)(uWS::WebSocket<true>,char *,size_t,uWS::OpCode))'
1> while trying to match the argument list '(bool, main::<lambda_f789fc974d6d87c4a2444e6ded66c2a0>)'

最佳答案

我遇到了同样的错误,经过小的修复后我让它运行了:

int main()
{ uWS::Hub h;

h.onMessage([](uWS::WebSocket<uWS::SERVER>* ws, char *message, size_t length, uWS::OpCode opCode) {
ws->send(message, length, opCode);
});

h.listen(3000);
h.run();
}

关于c++ - echo 示例编译错误 :ambiguous call to overloaded function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40041490/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com