OK, so I have two (completely unrelated, different project) classes using iterators now. One has iterator
and reverse_iterator
working as intended, and the other, current one has iterator
and a semi-broken const_iterator
(specifically, because const_iterator derives from iterator, the code LinkedList<int>::iterator i = const_list.begin()
is valid and allows you to modify the const defined list...).
I intend to add all four types to this class... If I can.
How would I proceed to minimize copy/pasting code and changing only the return type? Create a base class like base_iterator
to inherit from? Create an iterator
or const_iterator
and inherit from that? Inherit from some std:: class? If any of these cases are the "best" approach, what code goes where?
Perhaps none of the alternatives are good? I'm quite lost here, and can't find much reference material.
Any advice is appreciated, but please keep in mind that I'm new to the subject (both iterators and C++ in general, especially OOP). I've tried, in vain, to study the header files shipped with GCC - they're not exactly the tutorial I'm looking for.