operator ++/-- overloading in templates

Started by
9 comments, last by Jaiminho 16 years, 8 months ago
Quote:Original post by harmless
ah yes, the idea of having more than one iterator is nice. I would love to implement an iterator class, is there any good links that you know of that i can reference to in order to implement one?

Iterators classes are simply wrapped pointers. You have a pointer to your element (in this case, the list node) which is set to point to this->pNext and this->pPrev with the operators ++ and --. Aside from that, you need operators to compare (basically, only == and !=) the used iterator with one returned by a list method and an access operator to retrieve the data contents of the node, usually with unary operator * (you don't return a reference to the node, but a reference to the data). Of course, there are lots of complications and improvements done on std::list, but the basic is simply that.

You can google for the interface on std::list to check how it actually works. Anyway...

Quote:Original post by osmanb
Step away from the keyboard and go think about a more interesting programming problem.


Yes, it is a quite too simple programming problem.

This topic is closed to new replies.

Advertisement