二进制“==”:未找到运算符 - TCP 套接字 SFML

Binary '==': no operator found - TCP Socket SFML

我正在尝试遍历 std::list<sf::TcpSocket> clients 并从 sf::SocketSelector 和列表本身中删除断开连接的那些。 尝试使用迭代器从列表中删除客户端时,我不断收到 "binary '==' no operator found" 错误。 这是触发错误的代码部分:

std::list<sf::TcpSocket> clients;
std::list<sf::TcpSocket>::iterator i;

for (auto i = clients.begin(); i != clients.end();)
{
    if (selector.isReady(*i))
    {
        sf::Socket::Status status = i->receive(dummy, 1, received);
        if (status != sf::Socket::Done)
        {
            if (status == sf::Socket::Disconnected)
            {
                selector.remove(*i);
                clients.remove(*i);  // this causes the error
            }
        }
        else
        {
            //i++;
        }
    }
}

用它的迭代器删除对象,你已经有了它:

std::list<sf::TcpSocket> clients;
std::list<sf::TcpSocket>::iterator i;

for (auto i = clients.begin(); i != clients.end();)
{
    if (selector.isReady(*i))
    {
        sf::Socket::Status status = i->receive(dummy, 1, received);
        if (status != sf::Socket::Done)
        {
            if (status == sf::Socket::Disconnected)
            {
                selector.remove(*i);
                i = clients.erase(i); // Properly update the iterator
            }
        }
        else
        {
            ++i;
        }
    }
}