Essentially, this test program just creates a number of objects with different (x,y) positions and varying energy levels. Then I decrease each object's energy, and I want to be able to delete it if the energy level has reached zero.
The creation of the objects, and their placement into a vector of pointers works perfectly, but I cannot seem to access the members when I try to iterate through it, and I'm not really sure what's wrong with the syntax. Any help is appreciated...
You should be using line 70, not 69. but as (*iter)->dec etc
Line 71 is correct (but use -> not .). But then you must also remove that pointer from your vector using vector.erase(iter). The delete is only freeing the memory.
Remember that after you do an erase, the iterator is moved to the next object in the vector. Thats why using a for-loop is bad, your iter will be incremented and skip the next one.
Thanks. I guess I forgot to consider that the iterator is itself basically a pointer. As for the "for" loop, it's an easy problem to solve: in the "if " statement, all I have to do is decrement the iterator and no index will be missed.