std::list<int> myList;
std::list<int> myIter = myList.begin();
yineleyici sen myList.end()
ile başlatılıyor sanki aynı değere sahip. Yineleyici, uçtan uca konuma getirilir. Bir öğeyi listeye ittikten sonra bile yineleyici, bir-bir-sonuncu noktayı işaret eder. Onu artırırsanız, tanımlanmamış davranışları çağırıyorsunuz demektir.
GÜNCELLEME:
Örn Eğer -D_GLIBCXX_DEBUG ile GCC ile Snippet'inizi derlemek, eğer elde edilen yürütülebilir duracaktır:
/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
Bunun iyi bir soru olduğunu düşünüyorum çünkü bu beni gerçekten düşünmüştür, hmm, aslında. Bu bir liste ... belki bu işe yarayacak ... (Tabii ki) – jcoder