Let me start at a different point. Getting it explained from two directions is better than one.
[tt]list<typename T>[/tt] is a list of "T" objects. In our case, [tt]list<baseObject*>[/tt] is a list of pointers to baseObject.
Now, you don't know anything about how this "list" actually works internally. But you want to iterate through it. Luckily, the standard library defines a standard way to do so, and that is
iterators.
On any standard container, you can define an iterator, or a const_iterator if you want to make sure the container isn't modified.
Code: Select all
list<baseObject*>::const_iterator iter;
That's just such a thing: An iterator on a list of baseObject pointers. This iterator can "point" to an object of type [tt]baseObject*[/tt]. You can dereference it with [tt]*iter[/tt], you can make it point to the next object in the container by incrementing it, you can compare it to other iterators on the same container.
It behaves, for all practical purposes, like a pointer into an array. For many of the standard containers, that is exactly what an iterator actually
is. The good thing is, you don't have to know, really. It could be a hopelessly complex thing grabbing the next object over some kind of UDP network connection or something.
That is why you cannot initialize your iterator like a pointer, with, say, [tt]iter = &base_m[0];[/tt]. Luckily, the standard defines ways to do this, too: [tt]base_m.begin()[/tt] gives you an iterator pointing to the
first element, [tt]base_m.end()[/tt] gives you an iterator pointing to an element -
be careful now -
one behind the last element in the container. That means, dereference [tt]base_m.end()[/tt], you die.
Means, your code snippet is a loop that iterates through all elements of base_m, written as the C++ standard lib mandates.
And now you can surely tell me what
this little snippet does:
Code: Select all
for (list<baseObject*>::const_reverse_iterator iter = base_m.rbegin(); iter != base_m.rend(); ++iter)