• Advertisement

Archived

This topic is now archived and is closed to further replies.

Overloading pointer arithmetic

This topic is 5744 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

I'm trying to use pointer arithmetic with the standard library and I am feeling cramped. I am using the below iterator in my code. #include <list> using namespace std; typedef list::iterator LI; When I make a loop like this: for(LI i = polygonToSplit.begin(); i != polygonToSplit.end(); ++i){} I have to use ++i, or else I get an error. How do overload the +-*/ operators so I can incrimenta my loop by something like "i+2"? Thanks in advance. //Edit: Added the include and namespace [edited by - executor_2k2 on July 29, 2002 1:54:42 AM]

Share this post


Link to post
Share on other sites
Advertisement
I''ve been able to use the +/- operators with iterators. Have you tried "+=" or "-="? I don''t remember if they work or not. Otherwise you might try: ++(++it). That is one statement I''ve never tested, so I can''t tell you if it would work.

Share this post


Link to post
Share on other sites
i+=2 works. It would seem you have to modify "i" itself. Anyone know why? I need to find a way that doesnt change the value of i because im going to using the "+ 2" inside the loop, and I was hoping there was a clean way to access other elements in the array other than i without making a copy of i and incrimenting that copy with "++".

[edited by - executor_2k2 on July 29, 2002 3:00:29 AM]

Share this post


Link to post
Share on other sites
learn what you use

its a list
list doesn''t allow random access. you can''t simply jump to item i in it, you have to go trhough. a vector allows random access. not a list..

all in the docu

"take a look around" - limp bizkit
www.google.com

Share this post


Link to post
Share on other sites

  • Advertisement