Pushing a variable onto a vector, value at that point in vector changes when the variable does.
- by David Andrews
I have a programming problem =)
std::vector<char*> Names;
if(MyPacket.ID == 3)
{Names.push_back(MyPacket.Buffer);}
I push the recieved buffer onto a vector like so, but when the buffer changes so does the value of the variable at that point in the vector.
So say I sent and pushed a buffer containing 'Simon' onto the vector that would be fine so at point [0] on the vector would be the word Simon.
but then when I recieve a new buffer it overwrites position [0] even though the packets ID is different, a breakpoint within the if statement is not reached with this new buffer.
I really hope i'm explaining this well enough, I tried asking a friends advice and he pointed me towards this site.
Any help appreciated
David Andrews