std::list<int> myList;
std::list<int> myIter = myList.begin();
이터레이터는 myList.end()
으로 초기화하는 경우와 동일한 값을 갖습니다. 이터레이터는 지나친 끝 위치로 초기화됩니다. 엘리먼트를리스트에 넣은 후에도 반복자는 여전히 한 끝을 가리킨다. 증분하면 정의되지 않은 동작이 호출됩니다.
UPDATE :
예를 당신이 -D_GLIBCXX_DEBUG와 GCC와 조각을 컴파일하는 경우, 결과 실행이 중단됩니다
/usr/include/c++/4.6/debug/safe_iterator.h:236:error: attempt to increment
a past-the-end iterator.
Objects involved in the operation:
iterator "this" @ 0x0x7fffc9548fb0 {
type = N11__gnu_debug14_Safe_iteratorINSt9__cxx199814_List_iteratorIiEENSt7__debug4listIiSaIiEEEEE (mutable iterator);
state = past-the-end;
references sequence with type `NSt7__debug4listIiSaIiEEE' @ 0x0x7fffc9548fb0
}
zsh: abort (core dumped) ./listiter
내 생각에, 실제로는 이것이 좋은 질문이라고 생각합니다. 그것은 목록 일 것입니다 ... 어쩌면 이것이 작동 할 수도 있습니다 ... (물론 아닙니다) – jcoder