The problem is with the std::list<Felid*> getFelids()
method. It's returning the list by value, so every time you call it you get a new copy of the list. You should return a reference with std::list<Felid*>&
The segfault is because your iterator's begin()
and end()
are from different lists (because you're making a copy each time), so the iterator never reaches the end()
of the first list and keeps going through random memory.
Also, the list you're iterating through was just a temporary, so it's gone by the time you try to use the iterator.