Download

STD List Container

I came across something strange that I haven’t seen in C++ before. On line 35 I dereference a iterator like this:

(*iterator)

Why do I have to use the brackets and why does *iterator not work?

I posted the code on pastebin.com for code colors:

http://pastebin.com/vBtREHuH

That’s how you tell c++ what to do first.

And because iterators point to pointers It**?!

*(A)->Method(); tells the compiler to dereference A first then call Method();

More info here:
Pointers:
http://www.cplusplus.com/doc/tutorial/pointers/
Iterators:
http://www.cplusplus.com/reference/iterator/iterator/

As Azarus said, it’s an order of operations issue.

http://en.cppreference.com/w/cpp/language/operator_precedence

The indirect access operator (->) has higher precedence than the dereference operator (*). Putting (*iterator) makes sure that the dereference happens first.

Okay I see. Thanks!