Pointer on Iterator problem...

Discussion in 'C++' started by akush, Nov 27, 2003.

  1. akush

    akush Guest

    Hello!!

    i try to create a pointer on an iterator for a vector list ( with more
    than one values ). But if i iterate i only get the first value. if i
    want to get the next the program crahes. what i have made wrong?

    code example:

    TestList::iterator * listIter = new TestList::iterator();
    *listIter = list->begin();

    Test * tt1 = **listIter;
    **listIter++; // <--- works correct

    Test * tt2 = **listIter;
    **listIter++; // <--- crash

    Thanks for help
    akush
     
    akush, Nov 27, 2003
    #1
    1. Advertising

  2. akush

    Rolf Magnus Guest

    akush wrote:

    > Hello!!
    >
    > i try to create a pointer on an iterator for a vector list ( with more
    > than one values ).


    Why are you using pointers to iterators intead of the interators
    directly?

    > But if i iterate i only get the first value. if i
    > want to get the next the program crahes. what i have made wrong?
    >
    > code example:
    >
    > TestList::iterator * listIter = new TestList::iterator();
    > *listIter = list->begin();
    >
    > Test * tt1 = **listIter;
    > **listIter++; // <--- works correct


    I don't know what you want to increment (the iterator, or the list
    element?), but it increments the pointer to the iterator. So from now
    on, that pointer points beyond the iterator and must not be
    dereferenced anymore.

    > Test * tt2 = **listIter;
    > **listIter++; // <--- crash
     
    Rolf Magnus, Nov 27, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hendrik Maryns
    Replies:
    18
    Views:
    1,468
  2. greg
    Replies:
    6
    Views:
    483
    Dietmar Kuehl
    Jul 17, 2003
  3. Replies:
    6
    Views:
    698
    Jim Langston
    Oct 30, 2005
  4. Steven D'Aprano

    What makes an iterator an iterator?

    Steven D'Aprano, Apr 18, 2007, in forum: Python
    Replies:
    28
    Views:
    1,275
    Steven D'Aprano
    Apr 20, 2007
  5. Jim Anderson

    problem with iterator (map iterator)

    Jim Anderson, Jan 10, 2014, in forum: C++
    Replies:
    3
    Views:
    159
    Luca Risolia
    Jan 13, 2014
Loading...

Share This Page