所有
我有一些代码:
if (bind(this->socketListen, (SOCKADDR*)& this->addr, sizeof(this->addr)) == SOCKET_ERROR)
{
cerr << "Failed to bind the address to our listening socket. Winsock
Error:" << to_string(WSAGetLastError()) << endl;
exit(1);
}
此代码的第一行生成错误:
E0349 no operator "==" matches these oparands
和
C2678 binary '==': no operator found which takes a left-hand operand of type 'std::_Binder<std::_Unforces,SOCKET &,SOCKADDR *,unsigned int>'(or there is no acceptable conversion)
我该如何解决?
最佳答案
看起来编译器很容易将bind()
调用与std::bind
混淆。最有可能的原因是您之前写过using namespace std;
,并且包含了<functional>
标头。
最简单的解决方法是,您可以明确地告诉您要从全局名称空间获取bind()
:
if (::bind(this->socketListen, (SOCKADDR*)& this->addr, sizeof(this->addr)) == SOCKET_ERROR)
// ^^
最好是摆脱
using namespace std;
并使用特定的using
语句来满足namespace std
的需要,例如 using std::cin;
或在需要的地方简单地添加
std::
前缀。