I have this member function in my Folder class:
string _recFullPath() {
list<Folder*> folders;
list<Folder*>::iterator it = folders.begin();
folders.push_front(this);
it = folders.begin();
while((*it)->hasParent()) {
folders.push_front((*it)->parent());
it = folders.begin();
}
folders.push_back(this);
for(it = folders.begin(); it != folders.end(); ++it) {
cout << (*it)->getName() << "/";
}
}
This does compile, but when it comes to it = folders.begin(), in the while loop it gives a segmentation fault, and I cannot figure out why. The layout for a Folder object is this:
class Folder {
private:
Folder* _parent;
string _name;
string _fullPath;
string _recStrFullPath;
bool _hasParent;
public:
Folder(string name) {
this->_name = name;
this->_hasParent = false;
}
Folder(string name, Folder* parent) {
this->_parent = parent;
this->_name = name;
this->_hasParent = true;
}
Folder* parent() {
return this->_parent;
}
string getName() {
return this->_name;
}
};
And of course the above mentioned function. Can someone see what I'm doing wrong in the above code?