I've got a vector:
std::vector<C_Trigger*> tRegister;
Then I throw in pointers like this:
// trigger1 activates event1
C_Trigger* trigger1 = new C_Trigger(standOnTrigger); // Stand on cell trigger
trigger1->addEvent(event1);
tRegister.push_back(trigger1);
// trigger2 activates event2
C_Trigger* trigger2 = new C_Trigger(standOnTriggerAndKeyPress);
trigger2->addEvent(event2);
tRegister.push_back(trigger2);
Now, I would like to free up the memory I've allocated for trigger1 and trigger 2.
If Handle() returns true, that means the trigger has been used and should be deleted.
// Loop through triggers!
for(int i=0; i < tRegister.size(); i++) {
if(tRegister[i]->Handle()){ // True is set to kill! :D
// This is where the problem is..
C_Trigger* temp = tRegister[i];
delete temp;
tRegister.erase(tRegister.begin()+1);
}
}
I'm not too sure on the whole itterator idea.. Please, if you spot something I'd be really glad if you told me about it.
Cheers!
Here's the pastebin link, easier to read ;)
http://pastebin.com/d1db1036d