I’m returning iterator from my fnc after I used it and this iterator at the point of returning points to some character but after this fnc returns it the returned iterator doesn’t point to that character anymore. What am I doing wrong?
typename std::string::const_iterator return_iterator(const std::string& line)
{
auto beg = line.begin();
/*here I'm moving this iterator and assing to it i.e.*/
beg = line.begin() + some_position;
return beg;//at this point it points to a character
}
void other_fnc(const std::string& line)
{
auto pos = return_iterator(line);//after this fnc returns pos points to some rubbish
}
Any ideas?
I assume, the actual code probably has templates (
typenamedebris) and probably they are not referenced correctly in function argument of return type.The following code works as expected:
Verify your code according to it. If you are doing something else, update your question.
(PS: I got rid of
autoof C++11, as I don’t have the compliant compiler at the moment)