Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C - C++ Learning > Suggestions for...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 4249 of 4370
Post > Topic >>

Suggestions for Fixing Newbie Iterator Mistake?

by Larry Lindstrom <nobody@[EMAIL PROTECTED] > Aug 27, 2008 at 02:39 PM

Hi Folks:

    Developing on WinXP Home, VS 2008 Pro.

     By C++ standards, is it a problem if an iterator
referencing one list's element is tested against a
different list's end()?

    I'm keeping a test list, that contains no
elements, for the sole purpose of initializing new
iterators the value of this test list's end().
This test list will never contain elements.

    An iterator with a value of this list's end()
is analogous to a pointer with a value of NULL.

    The application might create a list, insert
valid data, and assign the iterator to elements
in this new list.  This list might never be created,
so I can't initialize the iterator to it's end().

    If the iterator is equal to the test list's end(),
I'm assuming it's not referencing an element in the
application's list.

    Is this a bad idea?

    I'm dusting off an application I wrote 4 years
ago, and Visual C 6.0 had no apparent problem with
this approach.

    Running this after a Visual Studio 2008 build
results in the application blowing up when testing
the iterator, now referencing a valid element in one
list, against the test list's end().

    Is there a way to make this test work?  Or do
I need to re-design my approach to test for valid
iterators?

                                          Thanks
                                          Larry
 




 4 Posts in Topic:
Suggestions for Fixing Newbie Iterator Mistake?
Larry Lindstrom <nobod  2008-08-27 14:39:30 
Re: Suggestions for Fixing Newbie Iterator Mistake?
Salt_Peter <pj_hern@[E  2008-08-27 22:14:47 
Re: Suggestions for Fixing Newbie Iterator Mistake?
Tomislav Petrovic <t.p  2008-08-28 09:02:38 
Re: Suggestions for Fixing Newbie Iterator Mistake?
Larry Lindstrom <nobod  2008-08-28 07:25:56 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Nov 21 14:32:35 CST 2008.