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 / Need help with deleting an Object from a Vector (Dynamic Array)

Author
Message
Lokiii
16
Years of Service
User Offline
Joined: 26th Oct 2008
Location:
Posted: 28th Oct 2008 03:03
Hey Everyone!

So I can't figure out how to erase an Object from a vector. In java its just Vector.Remove(int element#) but in C++ its iterators and some other wierd stuff. I've spent the last two hours trying to look it up and read on it and everytime by game crashes anyway. Here take a look.

-------------------------------------------------


------------------------------------------------------

vhBIt is my iterator
vhBullet is my vector for hBullet class
hBullet is my class for bullets. it creates and moves the 3d spheres
hB is the object from hBullet class


So this while loop keeps going until it goes through the whole vector and each iteration, it moves my bullet, and then checks if its out of bounds. If so, it should delete it. As soon as I go into the while loop the game crashes.

I have also tried this, but also to no luck:

-----------------------------------------------------------

-----------------------------------------------------------


Any advice?
Let me know if any more code/info needed.

Thanks, I really appreciate the help!
Lokiii
16
Years of Service
User Offline
Joined: 26th Oct 2008
Location:
Posted: 28th Oct 2008 04:55
Fixed it. Will post solution tomorrow.
Lokiii
16
Years of Service
User Offline
Joined: 26th Oct 2008
Location:
Posted: 28th Oct 2008 18:31
The culprit was vhBIt. Because I initialized it in the beginning of the program, it was empty when the loop ran through. The solution was to put it just above the while loop.

Login to post a reply

Server time is: 2024-11-25 05:42:37
Your offset time is: 2024-11-25 05:42:37