mylist.erase();を使用してリンクリスト内のノードを削除しようとしています。ですが、ノードはリストに残ります。 delete()を使用しようとしましたが、プログラムがクラッシュしました。何か案が?C++はリンクリスト内のノードを削除できません
list <Person*> :: iterator it;
it = gamelist.begin(); //gamelist is a <Person*> list. it is an iterator to this list.
while (it!=gamelist.end()){
if ((*it)->is_dead == true) {
delete (*it); //if I comment this line the program does not crash but the "dead" Person still remains in the list.
it = gamelist.erase(it);
}
else ++it;
}
こんにちはgamelist.eraseして削除しようとしましたか? –
こんにちは@JuanPablo。はい、私はそれを試しました。同じ問題... –
あなたはあなたが '新しい'メモリを '' 'それは、あなたは確かにそれは解放されていないのですか?あなたは一時的な 'Person *'に '* it'を保存して、その一時的なものを消去して削除することができます。 –