   Is there anything special to init an std::vector?
  do I need to do anything speical to an std::vector in my constructor/destructor code?  I''ve just been calling clear() on it, but now when i try to delete the BSP in my game engine, and then re load it, I am consistently having access violations when i try to use the vector.  And I''m not using a pointer to an std::vector either  
  But are you storing pointers in the vector, std::vector<Blaa*>? If you are, then you need to delete each of this pointers yourself. clear() only removes the raw pointers from the vector. ;#include <vector>#include <algorithm>template<class T>struct Deleter {    void operator()(T* obj) {   delete obj;    }};struct GameThing {};int main() {    std::vector<GameThing*> gamethings;    gamethings.push_back(new GameThing);    gamethings.push_back(new GameThing);    //delete the pointed to things    std::for_each(gamethings.begin(), gamethings.end(), Deleter<GameThing>());    //remove the pointers from the vector    gamethings.clear();    return 0;} [edited by - petewood on February 3, 2004 6:51:12 AM];  If you store objects rather than pointers to objects you can just do: #include <vector>struct GameThing {};int main() {    std::vector<GameThing> gamethings;    gamethings.push_back(GameThing());    gamethings.push_back(GameThing());    gamethings.clear();    return 0;} [edited by - petewood on February 3, 2004 6:53:47 AM];quote:Original post by petewood  If you store objects rather than pointers to objects you can just do:...Be aware though that when you store objects you will have a lot of copy-constructing going on. If this is a non-issue it''s way "easier" to put objects in (no deleting needed).What else comes to mind:When you put objects with pointers inside into your vector plus a destructor which deletes the pointers you better have a copy-constructor that''s aware of that. ;  you could use boost's smart_ptr (but not auto_ptr) to clean things up. That would give you the best of both worlds. Small copy construction overhead and dynamic memory. #include <vector>#include <algorithm>#include <boost/smart_ptr.hpp>struct GameThing {};int main() {    using boost::smart_ptr;    std::vector<smart_ptr<GameThing> > gamethings;    gamethings.push_back(new GameThing);    gamethings.push_back(new GameThing);    //delete and remove the pointers from the vector    gamethings.clear();    return 0;} [edited by - petewood on February 3, 2004 1:13:29 PM];  indeed, thats the approch i took when i had potentialy large objects which i was going to have to move from one list/vector to another, seemed like a sane way around the release problem and the large copying problem ;  Hey guys, this is the first time I could come back to check for responses.  You have all collectively answered my question, thanks a bunch guys ;  To petewood:Why? use boost''s smart_ptr ,but not auto_ptr ?  ;  well, for one thing, according to Effective STL, the use of them in containers is prohibited and it shouldnt even compile.The other reason is that when you copy an auto_ptr you change the value of the one you are copying for; auto_ptr<foo>pfoo1(new Foo);auto_ptr<foo)pfoo2(pfoo1);  // pfoo1 is now NULLpfoo1 = pfoo2;  // pfoo1 now has value, pfoo2 is NULLThis can cause horrible problems with things such as quicksort which do datacopying.Effective STL, item 8, page 40 for the full story 