Original Post
🔒 Locked
Pointers and STL
Advertisement
Quote:
Original post by DrEvil
KBOX * kbox = new KBOX;
kPipeline = kbox;
delete kbox;
Isn't pointer after delete kbox in kPipline invalid making kPipeline->SomeMethod() an access violation?
I think you want to do delete kPipeline, for all i, when you want to clear the kPipeline. Not right after you add the object pointer to the map.
Quote:
Original post by BlueHabu Quote:
Original post by DrEvil
KBOX * kbox = new KBOX;
kPipeline = kbox;
delete kbox;
Isn't pointer after delete kbox in kPipline invalid making kPipeline->SomeMethod() an access violation?
I think you want to do delete kPipeline, for all i, when you want to clear the kPipeline. Not right after you add the object pointer to the map.
ups! u'r right!
std::map<int,KBox*> kPipeline;void addKBOX(){ KBOX * kbox = new KBOX; kPipeline = kbox;}//to be called when you are done with the kPipeline mapvoid freeAllMemory(){ std::map<int,KBox*>::iterator ite = kPipeline.end(); for ( std::map<int,KBox*>::iterator it = kPipeline.begin(); it != ite; ++it ) { delete (*it).second; } kPipeline.clear();}Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement