【问题标题】:error C2678: binary '==': no operator found which takes a left-hand operand of type 'std::_Binder<std::_Unforced,SOCKET &,SOCKADDR *,unsigned int>'错误 C2678:二进制“==”:未找到采用“std::_Binder<std::_Unforced,SOCKET &,SOCKADDR *,unsigned int>”类型的左侧操作数的运算符
【发布时间】:2017-05-14 20:08:45
【问题描述】:

在这个函数中我看到了这个错误 错误 C2678:二进制“==”:未找到采用“std::_Binder”类型的左侧操作数的运算符(或没有可接受的转换)

void WComm::startServer(int port)
{
    // Connect to a server.
    con.sin_family = AF_INET;
    con.sin_addr.s_addr = inet_addr("0.0.0.0");
    con.sin_port = htons(port);
    if (bind(m_socket, (SOCKADDR*)&con, sizeof(con)) == SOCKET_ERROR)
    {
        printf("Failed to connect.\n");
        WSACleanup();
        return;
    }

    // Listen on the socket.
    if (listen(m_socket, 1) == SOCKET_ERROR)
    printf("Error listening on socket.\n");
}

有人帮我吗? 谢谢。

【问题讨论】:

  • 尝试用::bind 代替普通的bind。并改掉using namespace std;的习惯。编译器认为您是从标准库调用 std::bind,而不是从 Winsock API 调用 bind(由于后者在最后一个参数中的有符号/无符号不匹配,前者在重载决议中更匹配)。
  • @IgorTandetnik 应该作为答案发布。

标签: sockets visual-c++ operators


【解决方案1】:

正如 Igor 解释的“尝试 ::bind 而不是普通的 bind。编译器认为您正在从 标准库,而不是从 Winsock API 绑定。”

它对我有用。

【讨论】:

    猜你喜欢
    • 2020-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多