-1
我不明白为什么我得到这个错误,但同样的类在VS15下工作完美现在我使用VS12,这是一个简单的Winsock2实现,错误C2678:二进制'==':找不到操作符需要左手操作数
int Net::createServer(int port, int protocol)
{
int status;
// ----- Initialize network stuff -----
status = initialize(port, protocol);
if (status != NET_OK)
return status;
localAddr.sin_addr.s_addr = htonl(INADDR_ANY); // listen on all addresses
// bind socket
if (bind(sock, (SOCKADDR *)&localAddr, sizeof(localAddr)) == SOCKET_ERROR)
{
status = WSAGetLastError(); // get detailed error
return ((status << 16) + NET_BIND_FAILED);
}
bound = true;
mode = SERVER;
return NET_OK;
}
问题来源于这里
if (bind(sock, (SOCKADDR *)&localAddr, sizeof(localAddr)) == SOCKET_ERROR)
控制台日志:
error C2678: binary '==' : no operator found which takes a left-hand operand of type 'std::_Bind<_Forced,_Ret,_Fun,_V0_t,_V1_t,_V2_t,_V3_t,_V4_t,_V5_t,<unnamed-symbol>>' (or there is no acceptable conversion)
1> with
1> [
1> _Forced=false,
1> _Ret=void,
1> _Fun=SOCKET &,
1> _V0_t=SOCKADDR *,
1> _V1_t=size_t,
1> _V2_t=std::_Nil,
1> _V3_t=std::_Nil,
1> _V4_t=std::_Nil,
1> _V5_t=std::_Nil,
1> <unnamed-symbol>=std::_Nil
1> ]
使用_Winsock_你的代码的Ubuntu下工作?令人印象深刻... –
是的,这是一个错误 – Eddy
请发表[mcve],而不是这么大的代码转储。此外,你的包括警卫是非法的:https://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-ac-identifier –