iterators and class members

This is a discussion on iterators and class members within the C++ Programming forums, part of the General Programming Boards category; I read somewhere that when using iterators to refer to struct/class members that the arrow operator -> should not be ...

iterators and class members

I read somewhere that when using iterators to refer to struct/class members that the arrow operator -> should not be used and that the syntax should be (*it).member, or whatever. Is that correct? I read some about STL and such, but don't have compliant compiler so can't verify myself. Thanks.

Doing a brief scan of the standard, I can't find any mention of operator -> for iterators. However, code using iterator::operator-> compiles fine on Comeau C++ in strict mode, which is one of the most conforming compilers. Josuttis uses -> in "The C++ Standard Library", and Stroustrup uses it in "The C++ Programming Language", so I'd guess it is a safe practice.

pretty reputable sources, too, I'd say. I looked up my reference and it says that many iterator definitions do not overload the pointer operator...with these iterators field access must be performed using the combination of * and filed access dot, and not using the pointer arrow. (Budd---Data Structures in C++ using the STL. Therefore, it would seem that iterators don't come prequipped with the arrow operator like pointers do, so if you have problems using the pointer operator use the (*). syntax.