Jump to content
  • Advertisement
Sign in to follow this  
DOrmisher

Defining operators for an Iterator in a container class

This topic is 3651 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!