Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SOLVED]pointer erase std::vector  (Read 1750 times)

0 Members and 2 Guests are viewing this topic.

Soul

  • Newbie
  • *
  • Posts: 44
    • View Profile
[SOLVED]pointer erase std::vector
« on: March 02, 2013, 01:53:00 am »
hey, when i want erase pointer server stop working...

void Server::Recv()
{
    int id = 0;
    for ( std::vector<Client*>::iterator it = clients.begin(); it != clients.end(); ++it)
    {
        id++;
        Client &client = **it;
        client.ClientID = id;
        if ( Selector.isReady( client.Socket ) )
        {
            if ( client.Socket.receive( client.Recv ) == sf::Socket::Done )
            {
                std::string str, recv;
                std::ostringstream ss;
                client.Recv >> str;
                ss << client.ClientID;
                recv = "Received from ID: " + ss.str();
                recv += " " + str;
                Console::Out( recv.c_str(), str.c_str() );
                client.Recv >> str;
                if( str == "Bye" )
                {
                    Selector.remove( client.Socket );
                    str = "Client: " + ss.str() + " disconnected";
                    Console::Out( str.c_str() );
                    clients.erase( it );      // there
                }
            }
        }
    }
}

class Client
{
    public:
        sf::TcpSocket Socket;
        sf::Packet Send;
        sf::Packet Recv;
        int ClientID;
};
 

any ideas? : /
« Last Edit: March 02, 2013, 10:05:52 am by Soul »

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: pointer erase std::vector
« Reply #1 on: March 02, 2013, 03:11:55 am »
Related?

If not, what's "stop working"?

Soul

  • Newbie
  • *
  • Posts: 44
    • View Profile
Re: pointer erase std::vector
« Reply #2 on: March 02, 2013, 10:05:38 am »
yup, when i add return; after clients.erase(it); program work fine
thanks for help

 

anything