how to use iterator as parameter

hi experts, im trying to input iterator as parameter in a procedure

the linkedlist <char> contains 'a','b','c','d','e','f','g'

linked list is named "characters"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void modify()
{
   list<char>::iterator it1;
   list<char>::iterator it2;
   for(it1 = characters.begin(); it1 != characters.end(); it1++)
   {
      checkD(it1, it2)
      *it2 = *it1;
   }
}

void checkD(list<char>::iterator it1, list<char>::iterator it2)
{
   if(*it1 == 'd')
      *it2 = 'a';
}


in order to modify the elements in the list, can i pass the iterator in this way?
Yes, though you never set it2 to anything so you'll have a problem from that.
also note that checkD is pointless because you overwrite *it2 on line 8 anyway.

Maybe line 8 was supposed to be it2 = it1; ?
oh, yeah, i get it~! thank you
Topic archived. No new replies allowed.