简体   繁体   中英

How container class works in stl?

Iterator definition says [ 1 ]:

Iterator is an object enables programmer to traverse the container it also says Various types of iterators are often provided via a container's interface.

Cplusplus.com has a big table in which each container has member as iterator categories function.

So does it mean that each container class has iterator class which implements the base iterator class and various function in this iterator class which would instantiated and work with this container class in order to follow the interface.

My question is how a class allow another class to have interface?

C++ does not have a keyword interface . The (public) "interface" of a class is it's (public) members. This can include type aliases .

All the containers provide type aliases named iterator and const_iterator , which refer to types with the stated properties. They also have public member functions named begin and end , which are overloaded to return that container's iterator s and const_iterator s.

An Iterator is anything for which ++ advances and * dereferences. int * is one such type, so is _Tree_iterator<_Tree_simple_types<_Tmap_traits<int, int, ...>>> 1

The standard does not specify the type that vector<T>::iterator et.al. denote, only that it satisfies RandomAccessIterator .

  1. The (partial) type of Microsoft's version of std::map<int, int>::iterator

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM