Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / vector problem

Author
Message
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 6th Feb 2010 19:58 Edited at: 6th Feb 2010 19:59
Hello guys

i'm having a trouble with my vectors, first time i get such problem, whenever i used VectorName->push_back ( something ); all the members in the vector becomes same as the new element,here's the code:



after this code, both amt->MoveField members have the second value, all elements keeps getting same data as the last element, why is that? did i define vectors in a wrong way or something? im pretty sure i did the same thing with one of my programs and it worked well

dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 6th Feb 2010 20:34
Quote: "Array8x8 fld8x8;"


Quote: "amt->MoveField.push_back ( &fld8x8 );"


You do that twice, what do you think it's adding? It's just adding the same ptr twice, also, that ptr will become invalid once the function or whatever that's in returns. So you want to either dynamically allocate new instances of that struct, fill it and add it or write copies.

Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 7th Feb 2010 09:43
thanks man, i'm kinda weak at pointers, now it works

Login to post a reply

Server time is: 2024-11-20 05:31:00
Your offset time is: 2024-11-20 05:31:00