Pushing a variable onto a vector, value at that point in vector changes when the variable does.

Posted by David Andrews on Stack Overflow See other posts from Stack Overflow or by David Andrews
Published on 2011-01-15T00:34:08Z Indexed on 2011/01/15 0:53 UTC
Read the original article Hit count: 312

Filed under:
|
|

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

© Stack Overflow or respective owner

Related posts about networking

Related posts about vector