desktop wrote:
I am a bit confused. How will the compiler complain if a forward
iterator is just a variable name?
it won't complain.
The only way I can get it to report an
error is if I make my own class "class ForwarIterator" where I somehow
make it illegal to use "--".
Well, is not necessary to make the use of operator-- forbidden. It's
enough not to define it. Example, you write a very strange container
that for some really good reason ant to provide only the forward access
to the elements. You decide to implement the iterators for your
container, because it's a good and flexible way to access it (maybe is
not possible to access it like a normal vector, with []).
The you will write:
class MyContainerIterator
{
public:
bool operator==(const MyContainerIterator&) const;
const MyContainerIterator & operator==(const MyContainerIterator&);
MyType& operator*();
};
where MyType is the type of the elements of you container. The
implementation of the iterator will be more or less difficult depending
on your container.
and then, in your container:
class MyContainer
{
public:
typedef MyContainerIterator iterator;
iterator begin();
iterator end();
}
ok, now your container has got a forward iterator. When you want to use
it, you will define
MyContainer::iterator foo = mycont.begin();
you will be able to use it in all the stl functions that accept a
forward iterator, but if you put in some function that accept beckward
iterators, for example, the compiler will try to use the operator-- on
your Iterator class, and will complain because it haven't got it.
Regards,
Zeppe
has different names but you can use the same operators on them. And the