Hey guys, I was given a project that I have to complete that uses iterators everywhere. I found the iterator chart on the site, but I'm still confused as to what it actually means. Heres part of the article:
An iterator is any object that, pointing to some element in a range of elements (such as an array or a container), has the ability to iterate through the elements of that range using a set of operators (with at least the increment (++) and dereference (*) operators).
The most obvious form of iterator is a pointer: A pointer can point to elements in an array, and can iterate through them using the increment operator (++). But other kinds of iterators are possible. For example, each container type (such as a list) has a specific iterator type designed to iterate through its elements.
Notice that while a pointer is a form of iterator, not all iterators have the same functionality of pointers; Depending on the properties supported by iterators, they are classified into five different categories:...
So what does this mean when I'm given a function(inside a class) such as iterator FUNCTION_NAME()
or an argument variable (also inside a class) void FUNCTION_NAME(iterator VARIABLE) ???
I know I want to use a pointer, so does that mean I would pass a pointer variable through the function? Does that mean my iterator function is/can be a pointer?
It's true that pointers can be iterators, but iterators aren't only pointers. There are also std::iterators to consider, which is the type that those functions are taking/returning. Those iterators allow you to iterate over the data stored by the STL containers (for those containers that offer them, like array, vector, deque, list, map, and set).