By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,804 Members | 1,666 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,804 IT Pros & Developers. It's quick & easy.

(const) iterator question

P: n/a
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 ...
Mar 20 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
2b|!2b==? wrote:
If an iterator is a pointer, then why can't I assign an 'int' (NULL) to
it?
No reason. But an iterator is not a pointer.

Mar 20 '07 #2

P: n/a
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

Mar 20 '07 #3

P: n/a
On 3/20/2007 2:00 PM, 2b|!2b==? wrote:
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.
--
Stefan Naewe
stefan_DOT_naewe_AT_atlas_DOT_de
X-Replace-Address: yes
Mar 20 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.