When you do this:
vector<string>::const_iterator it = myObject->getList().begin();
At the end of the line, the iterator it
is invalid, because the vector<string>
returned by getList()
is a temporary value.
However, when you store the vector<string>
in a local variable, with
vector<string> myList = myObject.getList();
Then, the iterator remains valid, as long as myList
is not destroyed.