= !ObjectListIterator = [[TracNav(TracNav/TOC_Development)]] The !ObjectListIterator of a given class T can iterate exactly through all objects of class T and inheritors. The only way to create such an iterator is by calling one of [wiki:ObjectList ObjectLists] functions begin, end, rbegin or rend, where the !ObjectList has to be of the same T as the !ObjectListIterator. Another way to iterate through object-lists is by using [wiki:Iterator]. !ObjectListIterator however is much more performant as it knows about the right class an therefore needs no dynamic-cast. That's why you should always remember: '''Important''': Always use !ObjectListIterator instead of Iterator if you know which class you want to iterate through. == Notation == There are two equivalent notations: {{{ ObjectListIterator }}} and {{{ ObjectList::iterator }}} Use whatever you like. '''Important''': The second notation needs !ObjectList.h, while the first notation works already with a forward declaration. So if you need the iterator in a header-file, you should prefer the first notation. == Examples == {{{ for (ObjectList::iterator it = ObjectList::begin(); it != ObjectList::end(); ++it) { it->callSomeFunction(...); myClass* storeTheObject = (*it); } }}} The following example uses the class-tree below: {{{ #!cpp new A1(); new A1(); new A1(); new A3(); new A3B1(); new A3B1C1(); int count = 0; for (ObjectList::iterator it = ObjectList::begin(); it != ObjectList::end(); ++it) { count++; } std::cout << "BaseObject: " << count << std::endl; count = 0; for (ObjectList::iterator it = ObjectList::begin(); it != ObjectList::end(); ++it) { count++; } std::cout << "A1: " << count << std::endl; count = 0; for (ObjectList::iterator it = ObjectList::begin(); it != ObjectList::end(); ++it) { count++; } std::cout << "A3B1: " << count << std::endl; /* return: BaseObject: 6 A1: 3 A3B1: 2 */ }}} [[Image(Core:testclass_tree.gif)]]