Sign in to follow this  

Defining operators for an Iterator in a container class

This topic is 3311 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm creating a multi-set container class and I have defined an iterator like so:
typedef CObject<T>* iterator;
I want to define the increment operator for my iterator so it can increment through a vector in the multiset class that holds all the objects in the multiset. However, when I define the operator like so:
iterator operator ++()
{
   iterator = iterator->GetNext();
}
And I try to use the iterator in my main function like this...
for(Iter = m.Begin(); Iter != m.End(); Iter++)
{		
}
...it seems as if the incrementing is simply moving the pointer to the next block of memory or something, instead of doing my defined ++ Can anyone help? Thanks

Share this post


Link to post
Share on other sites
Quote:
Original post by DOrmisher
...it seems as if the incrementing is simply moving the pointer to the next block of memory or something, instead of doing my defined ++
That is exactly what it is doing, because for some reason you are using a pointer to your iterator - so the increment applies to the pointer instead. Iterators need to be held by value if you want operators to work.

Share this post


Link to post
Share on other sites

This topic is 3311 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this