problem passing list iterator

Discussion in 'C++' started by vfunc@talktalk.net, Mar 16, 2006.

  1. Guest

    I want to pass a list "node" to a function, read only access of the
    list is fine, this is the relevant code I have so far

    typedef std::vector<double> myvec;
    typedef std::list<myvec> mylist; // a list of vectors
    typedef mylist::const_iterator myiter;

    void a(myiter &x)
    {
    int i;
    ....
    // do something with
    x
    };

    The compiler does not like x
    "no match for operator [] .."
    why is that?

    How can I access the node like as if it were a myvec (by reference is
    nice if that is OK).

    Thanks.
     
    , Mar 16, 2006
    #1
    1. Advertising

  2. Kai-Uwe Bux Guest

    wrote:

    > I want to pass a list "node" to a function, read only access of the
    > list is fine, this is the relevant code I have so far
    >
    > typedef std::vector<double> myvec;
    > typedef std::list<myvec> mylist; // a list of vectors
    > typedef mylist::const_iterator myiter;
    >
    > void a(myiter &x)
    > {
    > int i;
    > ...
    > // do something with
    > x


    Try:

    (*x)

    or

    x->operator[](i)

    or, if you want range checking

    x->at(i)

    > };
    >
    > The compiler does not like x
    > "no match for operator [] .."
    > why is that?


    The object x is not a vector but an iterator pointing to a vector.

    > How can I access the node like as if it were a myvec (by reference is
    > nice if that is OK).


    see above.


    Best

    Kai-Uwe Bux
     
    Kai-Uwe Bux, Mar 16, 2006
    #2
    1. Advertising

  3. Guest

    Thanks for that. I have one remaining related problem now, the
    function

    void b(myiter &a)

    compiles OK, but when it is called with

    myiter x;
    ....
    b(x++)

    the compiler complains "no matching function call..."
     
    , Mar 16, 2006
    #3
  4. Guest

    wrote:

    > Thanks for that. I have one remaining related problem now, the
    > function
    >
    > void b(myiter &a)
    >
    > compiles OK, but when it is called with
    >
    > myiter x;
    > ...
    > b(x++)
    >
    > the compiler complains "no matching function call..."


    OK, it was the ++ it did not like.
     
    , Mar 16, 2006
    #4
    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,457
  2. Replies:
    6
    Views:
    683
    Jim Langston
    Oct 30, 2005
  3. Replies:
    1
    Views:
    298
    Marcus Kwok
    Mar 16, 2006
  4. David Bilsby
    Replies:
    5
    Views:
    2,080
    David Bilsby
    Oct 9, 2007
  5. Jim Anderson

    problem with iterator (map iterator)

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

Share This Page