QOTD
-
Michael Dunn wrote: You can't make any assumptions about it actually being a pointer to the underlying data, because iterator is not documented as such. But you can expect it to support (part of) the syntactic interface of a pointer (operator *(), operator ->() and for some iterators also operator []()) Therefore if you use it in generic (templated) code you can expect it to work like a pointer. We have to be very careful with terms like "pointer", "data" and so on here. What exactly is meant by "pointer". A pointer in the C sense or a "thing" that supports the interface of a pointer and therfore acts like a pointer (which is exactly the idea of a generic iterator used in STL). I am still not sure about the intention of the original question: Given an STL iterator it, what is the correct way to access a pointer to the iterator's data? Does it mean:
- a C-style pointer to the data the iterator refers to? Then the correct answer is c), even if I am not sure it should be written as &(*it) instead of &*it .
- a "pointer interface" to the data the iterator refers to? Then the correct answer is a).
- a "pointer inteface" to the iterator itself? Then the correct answer is b).
- ...
-- Daniel Lohmann http://www.losoft.de (Hey, this page is worth looking! You can find some free and handy NT tools there :-D )
Daniel Lohmann wrote: But you can expect it to support (part of) the syntactic interface of a pointer (operator *(), operator ->() and for some iterators also operator []()) Therefore if you use it in generic (templated) code you can expect it to work like a pointer. Try it in VC 7 and see what happens :) Daniel Lohmann wrote: a C-style pointer to the data the iterator refers to? Then the correct answer is c), even if I am not sure it should be written as &(*it) instead of &*it . Did I not put a bracket ? My bad. This is what I meant by the question though. Christian We're just observing the seasonal migration from VB to VC. Most of these birds will be killed by predators or will die of hunger. Only the best will survive - Tomasz Sowinski 29-07-2002 ( on the number of newbie posters in the VC forum ) Cats, and most other animals apart from mad cows can write fully functional vb code. - Simon Walton - 6-Aug-2002
-
Daniel Lohmann wrote: I am still not sure about the intention of the original question: It's not that complicated. An iterator is not a pointer. "pointer" meaning "C-style pointer". iterator overloads pointer operators so you can treat it as a pointer, but that's a different story. (iterator has a ++ operator, does that make it a number?) Are we next going to debate about what the meaning of the word "is" is? ;) --Mike-- Just released - RightClick-Encrypt v1.3 - Adds fast & easy file encryption to Explorer My really out-of-date homepage Sonork-100.19012 Acid_Helm
Michael Dunn wrote: (iterator has a ++ operator, does that make it a number?) Operator ++ - hey, that makes it a pointer! ;P ;P :-D -- Daniel Lohmann http://www.losoft.de (Hey, this page is worth looking! You can find some free and handy NT tools there :-D )