(const) iterator question

2

2b|!2b==?

If an iterator is a pointer, then why can't I assign an 'int' (NULL) to it?

This works fine in debug, but fils to compile with Release configuration ..:


bool myParser::spellCheck(TokenList tokenList) {
TokenIterator tokenIterator = tokenList.begin();
TokenIterator lastSignificantToken = NULL; // <- complier to barfs here
....

Notes:
TokenIterator is typedefed as a const_iterator to a vector of tokens ...
 
S

Stefan Naewe

If an iterator is a pointer,

Who said that ?
then why can't I assign an 'int' (NULL) to it?

Because it is no pointer!
This works fine in debug, but fils to compile with Release configuration
..:


bool myParser::spellCheck(TokenList tokenList) {
TokenIterator tokenIterator = tokenList.begin();
TokenIterator lastSignificantToken = NULL; // <- complier to barfs here

Try:

TokenIterator lastSignificantToken = tokenList.end();

Notes:
TokenIterator is typedefed as a const_iterator to a vector of tokens ...

S.
 
P

pasalic.zaharije

If an iterator is a pointer, then why can't I assign an 'int' (NULL) to it?
This works fine in debug, but fils to compile with Release configuration ..:


bool myParser::spellCheck(TokenList tokenList) {
TokenIterator tokenIterator = tokenList.begin();
TokenIterator lastSignificantToken = NULL; // <- complier to barfs here
...

Notes:
TokenIterator is typedefed as a const_iterator to a vector of tokens ...
If an iterator is a pointer, then why can't I assign an 'int' (NULL) to it?

Nope, iterator IS NOT pointer.
TokenIterator lastSignificantToken = NULL; // <- complier to barfs here

There is no NULL for iterators. You can use container.end() to mark
iterator
as 'no-value'. Note, that after isertion/delete/... this iterator is
invalid, and you
must assign container.end() to it again.

Best,
Zaharjie Pasalic
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top