= HowTo: ObjectLists and Iterators = [[TracNav(TracNav/TOC_Development)]] == Description == Every instance of a class which is in the [wiki:howto/ClassHierarchy class hierarchy] is stored in a [wiki:ObjectListBase list]. Additionally it's stored in the lists of all classes it is derived. So in the list of "BaseClass" you'll find instances of "BaseClass" '''and''' "DerivedClass" (if DerivedClass is derived from BaseClass as the names suggest). Of course it's possible to iterate through all instances of a class. This is achieved by using iterators. There are two types: [wiki:ObjectListIterator] and [wiki:Iterator]. This page explains the difference and how to use them. == !ObjectListIterator == An !ObjectListIterator is used if you know at compiletime through which class you want to iterate. {{{ for (ObjectList::iterator it = ObjectList::begin(); it != ObjectList::end(); ++it) { it->callSomeFunction(...); MyClass* storeTheObject = (*it); } }}} See [wiki:ObjectListIterator] for detailed information. == Iterator == An Iterator is used if the class through which you want do iterate is determined at runtime. This is slower than !ObjectListIterator. {{{ Identifier* identifier = someFunctionReturningAnIdentifier(); for (Iterator it = identifier->getObjects()->begin(); it != identifier->getObjects()->end(); ++it) { it->callSomeFunction(...); BaseObject* storeTheObject = (*it); } }}} See [wiki:Iterator] for detailed information.