iterator for two lists

Discussion in 'C++' started by swtsvn, Sep 11, 2008.

  1. swtsvn

    swtsvn Guest

    hi all
    iam having two lists
    list<float*> scan[10];

    list<float*> AET;
    and if i call list<float*>::iterator i;
    the scan array of list pointers is getting referenced by the iterator

    how do i access the iterator for AET which is just a general list

    thanks
    swtsvn, Sep 11, 2008
    #1
    1. Advertising

  2. swtsvn

    Rolf Magnus Guest

    swtsvn wrote:

    > hi all
    > iam having two lists
    > list<float*> scan[10];


    Actually, you already have 10 lists here.

    > list<float*> AET;


    And here is another one, so it's a total of 11.

    > and if i call list<float*>::iterator i;


    You can't "call" an iterator. What do you mean by that?

    > the scan array of list pointers is getting referenced by the iterator


    There is no array of list pointers. There is an array of lists, each
    containig float pointers.

    > how do i access the iterator for AET which is just a general list


    Just the same as you would for an element of your array. It's the same type,
    and the iterator type for it is also list<float*>::iterator.

    I'm not sure if that answered your question. Could you give an example of
    how you try to use your iterators and lists and what problems you're
    running into?
    Rolf Magnus, Sep 11, 2008
    #2
    1. Advertising

  3. swtsvn 写é“:
    > hi all
    > iam having two lists
    > list<float*> scan[10];
    >
    > list<float*> AET;
    > and if i call list<float*>::iterator i;
    > the scan array of list pointers is getting referenced by the iterator
    >
    > how do i access the iterator for AET which is just a general list
    >
    > thanks


    I don't quite understand what your design does.

    Why a list of pointers?

    Usully the STL containers are used on objects or something.

    Do you mean you need this:?

    typedef std::list<std::auto_ptr<float> > list_t;

    list_t AET;

    list_t::iterator iter= AET.begin();

    now you can use iter as an iterator.

    But it is not good to store auto_ptr in list.
    So you need to make your intention more clear.

    Hope may help.
    书呆彭, Sep 11, 2008
    #3
  4. swtsvn

    James Kanze Guest

    On Sep 11, 7:18 am, ??? <> wrote:

    [...]
    > Do you mean you need this:?


    > typedef std::list<std::auto_ptr<float> > list_t;


    That's not legal. You're not allowed to instantiate a list with
    auto_ptr.

    > But it is not good to store auto_ptr in list.


    It's not allowed by the standard. It's undefined behavior.

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
    James Kanze, Sep 11, 2008
    #4
  5. swtsvn

    swtsvn Guest

    hi all
    i found the solution
    though both has list<float*>::iterator type, when i use it in the for
    loop, i take the begin and end of the respective lists
    for eg

    my working code
    list<float*>::iterator i,j;

    for(k=0;k<10;k++){

    for(i=scan[k].begin();i<scan[k].end();i++){
    //do my work here
    }
    }

    for(j=AET.begin();j<AET.end();j++){
    //do my work here
    }
    i do not have my full code with me now,
    so plz forgive me for any syntax error.
    the reason y i need an array of (pointers to lists) is that
    iam implementing scan line polygon fill algorithm for my class
    assignment,
    and the scan array is the edge table datastructure
    and the AET list is the active edge table datastructure
    hope i ve made my intentions clear

    On Sep 11, 3:33 am, James Kanze <> wrote:
    > On Sep 11, 7:18 am, ??? <> wrote:
    >
    > [...]
    >
    > > Do you mean you need this:?
    > > typedef std::list<std::auto_ptr<float> > list_t;

    >
    > That's not legal. You're not allowed to instantiate a list with
    > auto_ptr.
    >
    > > But it is not good to store auto_ptr in list.

    >
    > It's not allowed by the standard. It's undefined behavior.
    >
    > --
    > James Kanze (GABI Software) email:
    > Conseils en informatique orientée objet/
    > Beratung in objektorientierter Datenverarbeitung
    > 9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
    swtsvn, Sep 15, 2008
    #5
    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,399
  2. greg
    Replies:
    6
    Views:
    444
    Dietmar Kuehl
    Jul 17, 2003
  3. =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==

    List of lists of lists of lists...

    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==, May 8, 2006, in forum: Python
    Replies:
    5
    Views:
    384
    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==
    May 15, 2006
  4. Replies:
    6
    Views:
    628
    Jim Langston
    Oct 30, 2005
  5. Steven D'Aprano

    What makes an iterator an iterator?

    Steven D'Aprano, Apr 18, 2007, in forum: Python
    Replies:
    28
    Views:
    1,132
    Steven D'Aprano
    Apr 20, 2007
Loading...

Share This Page