Explanation of ::iterator

EMBED

Thu Apr 15 2021 19:48:48 GMT+0000 (UTC)

Saved by @wowza12341 #c++


Simple explanation: Iterators are used to point at the memory addresses of STL containers. The iterator for a container is defined as a nested class within the container. So the class definition for std::vector contains the definition of a vector iterator as an inner class of the vector, if you like. What is the type of this iterator? C++ says that it is the type of the outer class, followed by the scope operator ::, followed by the name of the inner class. So if we have a vector of int, the type of the outer class is vector<int> and the type of the iterator for this is vector<int>::iterator. The begin() member function of the vector class returns an iterator, and this iterator will have this type. So we can store this iterator by doing vector<int>::iterator b = some_vec.begin();

https://www.udemy.com/course/learn-advanced-c-programming/learn/lecture/3688274#questions/10258738