-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 –