my_list
is declared as pass-by-value, it's a copy from the argument. That means, given distance(my_list.begin(),_start);
, my_list.begin()
and _start
point to two different std::list
s, the behavior is undefined.
If you change it to pass-by-reference, then both the iterators point to the same std::list
and the code would be fine. e.g.
void xx(list<int>& my_list, list<int>::iterator start){
list<int>::iterator _start = start;
distance(my_list.begin(),_start);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…