So i'm working on a client/server application and in server i have this: std::vector<Client*> *clients; and i'm using client->push_back(*clientA) to add objects in it. Once client ends connection i clear data of that client in vector. So lets say i have 10 clients in vector and client number 3-5-8 disconnects. What i wanna do is remove those objects from vector and push other ones near to index 0 so that the next client i add will be placed at index 7 instead of 10. Is that possible ?
you could (i think) reverse-iterate through the vector and check each client number. when you come across a relevant client to delete erase this element. and remember to free up any corresponding memory.
Thanks for your reply. I figured that if i use vector::erase() it will automatically change position of rest of objects which will reduce size of vector. Problem solved.
Oh you're right if both 4th and 5th clients disconnects at the same time i wont be able to erase 5th in first loop since it'll be actually 4th after erasing 4th. Thanks! :)