Re: (const) iterator question
On Mar 20, 4:11 pm, r...@your.box.com ("2b|!2b==?") wrote:
If an iterator is a pointer, then why can't I assign an 'int' (NULL) to it?
I don't know whether your iterator is a pointer, perhaps yes,
perhaps not. Iterator's are generalized pointers and every
pointer fulfills all requirements of an iterator, but not
vice versa.
This works fine in debug, but fails to compile with Release
configuration ..:
bool myParser::spellCheck(TokenList tokenList) {
TokenIterator tokenIterator = tokenList.begin();
TokenIterator lastSignificantToken = NULL; // <- complier barfs here
..
Notes:
TokenIterator is typedefed as a const_iterator to a vector of tokens ...
Your code does assume that the statement
TokenIterator lastSignificantToken = NULL;
is valid. Generally it is not so, because you don't know
what TokenList::const_iterator actually is and you should
not know that. It's quite unusual that under debug conditions
the assignement where well-defined, but that is all what
I can say without knowing the concrete standard library
implementation.
I propose that you use boost::optional<TokenIterator>
or simply a std::pair<TokenIterator, bool> where the bool
value signales whether first has already been set.
Greetings from Bremen,
Daniel Kr?gler
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]