Two "seemingly" similar pieces of code and need help

So I have pasted the two functions below that I'm getting issues from. The top one works fine, but for some reason the bottom one gives me an error for the "=" when saying it=ll.begin()saying no operand exists. Can anyone plz help me out?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void LListJar::remove(const Marble& m)
{
   list<Marble>::iterator i;

   for (i = ll.begin(); i != ll.end(); ++i)
      if (*i == m) {
         ll.erase(i); // make yourself familiar with the functions of
                      // list class in STL, e.g. erase
         break;
      }
}

const Marble& LListJar::get_elem(int i) const
{
	list<Marble>::iterator it;

	for (it = ll.begin(); it != ll.end(); ++it) {}
}
closed account (D80DSL3A)
Please always give the actual error message. That can help us to interpret the problem better.

I suspect the problem is that the wrong iterator type is being used in the 2nd function.
The function get_elem() is declared as constant:
const Marble& LListJar::get_elem(int i) const<- the const at the end

This means that it won't allow changes to be made to the calling object.
The member ll could be changed using list<Marble>::iterator it;.
Try using list<Marble>::const_iterator it; instead.
Thank you that was it. Kinda stumped on my function though. Do you know how I could go about getting an element of the list when the user types in the number of the element they want?
I thought I could just have a for loop until the iterator equals "i" but iterators don't work that way.
Topic archived. No new replies allowed.