Let it be std::list::iterator and std::list::reverse_iterator. Is reverse one derived from forward? And if not then why there’re not reverse equivalents for member functions of list?
Thanks in advance.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Not necessarily, they may (and probably are in most implementations) different types. Iterators are copied around all the time, and this inheritance would cause slicing. Plus, all operations on
iteratorshould bevirtualto avoid inconsistencies, which would be inefficient. Thinking about it, it would make sense for the standard to even forbid inheritance as a possible implementation (and maybe it does, indirectly).Update: The standard provides a definition for
std::reverse_iteratorclass template, and mandates thatstd::list::reverse_iteratoris a specialization of such template. Inheritance is not a possible implementation.Because you can call
base()on areverse_iteratorto get the underlying regulariterator. The fundamental relation between areverse_iteratorand its correspondingiteratoriis that&*(reverse_iterator(i)) == &*(i - 1).