I'm learning C++, and now I have problems with iterators. This is my case: I have this code here.
// std::list<Dragon*> dragons = cave.getDragons();
for (std::list<Dragon*>::iterator it = cave.getDragons().begin(); it != cave.getDragons().end(); it++){
os << std::endl << (*it)->getName();
}
It returns a Segmentation fault. This is my list and my getDragons() method:
std::list<Dragon*> dragons;
std::list<Dragon*> getDragons() const {return dragons;}
And my question is... Why do I have a Segmentation fault doing that like this, but if I use dragons variable, which is commented, don't? Thanks!
Aucun commentaire:
Enregistrer un commentaire