In article < .com>,
"RishiD" <> wrote:
> Hi,
>
> I am using an iterator on a list, I wanted to know is there a simple
> way to erase() the current element the iterator is pointing to and move
> the iterator forward one?
Yes, simply call erase() and assign the return value to the iterator
object passed in.
> The only way I can think of doing this is making a temp iterator equal
> to orig position, then erasing, and setting the original iterator to
> temp iterator++
>
> Basically asking if there is a way to do the code below in two steps
> instead of three.
>
> Thanks,
>
> RishiD
>
> // move private iterator forward and eliminate person
> void movingForward()
> {
> list<Person>::iterator tempIter = privIter;
> circle.erase(privIter);
> privIter = tempIter++;
> }
void movingForward()
{
privIter = circle.erase( privIter );
}
or since you are working with a list, you could:
void movingForward()
{
circle.erase( privIter++ );
}
--
To send me email, put "sheltie" in the subject.
|