Search code examples
c++c++11iteratordeque

Is this valid when dereferencing an iterator


 for (auto iter = dlQueue.cbegin(); iter != dlQueue.cend(); ++iter)     
        {
                // reference to the current element in the container
                if (*iter.id == listid)
                {
                        *iter.stall = newstall & 0xFFFFFFF;
                }
        }

when I dereference the object iter refers to will I be able to check the state of the object; ie id. Or will this just give me an iterator in return.

I can't go:

iter -> id

DlQueue is a dequeue.


Solution

  • No, the code you quote is wrong.

    . has higher precedence than unary *. To access a member of the element referred to by iter you should write (*iter).id or iter->id, not *iter.id.