"Azumanga" <azumanga@bubblescope.net> wrote in message
news:cftclm$e9f$1@pump1.york.ac.uk...[color=blue]
> I am trying to define a series of iterators for a container I am
> building, and as forward, bidirectional and random access iterators[/color]
are[color=blue]
> very similar I thought it would be handy to put them into a[/color]
heirachy,[color=blue]
> much like the code below:
>
> struct MyForwardIterator {
> typedef forward_iterator_tag iterator_category;
> // forward iterator functions
> };
>
> struct MyBidirIterator : public MyForwardIterator {
> typedef bidirectional_iterator_tag iterator_category;
> // extra bidir functions
> };[/color]
<snip>
[color=blue]
> While this appears to work fine, I feel a little nervous about
> overloading typedefs in the different classes. Should I be worried[/color]
and[color=blue]
> is there any unpleasent errors that could arise from this kind of[/color]
thing?
I wouldn't worry about hiding the typedefs from the base classes since
users will see the types of the iterators as container::iterator and
won't know about the base classes.
I would worry about writing conforming iterators, however, since it's
tricky. I'd recommend at least looking at the boost iterator library
before writing iterators from scratch.
(
http://www.boost.org/libs/iterator/doc/index.html)
Jonathan