473,320 Members | 1,794 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

(const) iterator question

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
3 1454
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Christof Krueger | last post by:
Hello, I'm quite new to C++ so maybe there's something I miss. I write a simple board game. It has a board class. This class has a method that returns the count of pieces a player has on the...
26
by: Michael Klatt | last post by:
I am trying to write an iterator for a std::set that allows the iterator target to be modified. Here is some relvant code: template <class Set> // Set is an instance of std::set<> class...
4
by: NKOBAYE027 | last post by:
Hi Everyone: Short description first MathematicalSet is to be a class template that's supposed to behave as the name suggests. It has functions that define union, contains, is_contained_in,...
7
by: Siemel Naran | last post by:
Hi. I have a function template <class InputIter, class OutputIter> void f(InputIter begin, InputIter end, OutputIter result); With c of type char* and cc of type const char*, the code...
11
by: snnn | last post by:
On the book <Generic Programming and the STL>( Matthew . H . Austern ),this function is defined as iterator set::begin() const. However, why should a const object returns a non-const iterator?...
6
by: PengYu.UT | last post by:
Hi, Suppose I have a list which contains pointers. I want the pointer got by dereferencing the iterator be a pointer pointing to a const object. But std::list<const T*>::const_iterator doens't...
4
by: chrisstankevitz | last post by:
This code does not compile on gcc 3.4.4. Should it? Thanks for your help, Chris //================ #include <set> int main()
2
by: Lorenzo Castelli | last post by:
This is an old problem of mine. Basically I have an abstract base class which represents a generic iterator over a collection of elements, and various derived classes that implement the...
0
by: wellingj | last post by:
A little back ground on what I'm trying to do: I'm making a generic weighted graph class (vertexes and edges althought I don't call them that) to implement some pathfinding algorithms like A* and D*....
3
by: jarek | last post by:
Hi! How can I declare iterator to const object ? I've the following: class ClassA : public list<ClassB> { ..... }
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.