The code is here. It's almost 1000 lines. The first 800 lines are just class and declaration. The problem start at around line 910+.
http://cpp.sh/7qrh[
^]
I have this code here, it compiles ok.
But it crashes when executing pop_back() on the vector in line 919.
It crashes and show the memory header file (which I don't know how to read).
The error is 'pointer being freed was not allocated'.
I'm still learning and didn't know much about debugging.
This is some lines from the code.
template <typename A, typename B>
void battle(vector<A> &human, vector &zombie){
while (!human.empty() || !zombie.empty()){
human.pop_back();
}
}
In main, I have this.
vector<unique_ptr<Warrior>> warriors;
vector<unique_ptr<Knight>> knights;
vector<unique_ptr<Goblin>> goblins;
vector<unique_ptr<Orc>> orcs;
battle(warriors, goblins);
I just want to understand why this happen?
What can I do to improve my code?
Update:
new code :
http://cpp.sh/4pcg[
^]