Overloading pointer arithmetic

Started by
2 comments, last by executor_2k2 21 years, 8 months ago
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]
Well, that was a waste of 2 minutes of my life. Now I have to code faster to get 'em back...
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.
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]
Well, that was a waste of 2 minutes of my life. Now I have to code faster to get 'em back...
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
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

This topic is closed to new replies.

Advertisement