hi ng,
i'm working on a multiplayer game for a variable number of players and on the client side, i'm using a std::vector<CPl ayer> to store
informatik about the players. CPlayer is a class that contains another std::vector<CPo sition>. Because one of the players is the
client itself (and the size of the vector<CPlayer> doesn't change during a game), i thought i could store a
std::vector<CPl ayer>::iterator "localplaye r" that points to the respective element of the vector.
The strange thing is that when i add elements to the std::vector<CPo sition> (which is nothing more than a usual member of CPlayer)
the iterator "localplaye r" becomes somehow invalid (in a way that the memory it points to is no longer the actual "localplaye r" but
rather some random position in memory). what's wrong here? i didn't change anything about the std::vector<CPl ayer> so why can't i
use the "localplaye r" iterator any more? and: would it help to store a reference to the element rather than an iterator? i fixed
this problem by using an index instead of iterator, but i'm really curious about this.
thanks in advance
janina
i'm working on a multiplayer game for a variable number of players and on the client side, i'm using a std::vector<CPl ayer> to store
informatik about the players. CPlayer is a class that contains another std::vector<CPo sition>. Because one of the players is the
client itself (and the size of the vector<CPlayer> doesn't change during a game), i thought i could store a
std::vector<CPl ayer>::iterator "localplaye r" that points to the respective element of the vector.
The strange thing is that when i add elements to the std::vector<CPo sition> (which is nothing more than a usual member of CPlayer)
the iterator "localplaye r" becomes somehow invalid (in a way that the memory it points to is no longer the actual "localplaye r" but
rather some random position in memory). what's wrong here? i didn't change anything about the std::vector<CPl ayer> so why can't i
use the "localplaye r" iterator any more? and: would it help to store a reference to the element rather than an iterator? i fixed
this problem by using an index instead of iterator, but i'm really curious about this.
thanks in advance
janina
Comment