problem passing list iterator

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vfunc@talktalk.net

    #1

    problem passing list iterator

    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<dou ble> myvec;
    typedef std::list<myvec > mylist; // a list of vectors
    typedef mylist::const_i terator myiter;

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

    The compiler does not like x[i]
    "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.

  • Marcus Kwok

    #2
    Re: problem passing list iterator

    vfunc@talktalk. net <vfunc@talktalk .net> wrote:[color=blue]
    > 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<dou ble> myvec;
    > typedef std::list<myvec > mylist; // a list of vectors
    > typedef mylist::const_i terator myiter;
    >
    > void a(myiter &x)
    > {
    > int i;
    > ...
    > // do something with
    > x[i]
    > };
    >
    > The compiler does not like x[i]
    > "no match for operator [] .."
    > why is that?[/color]

    x is a const_iterator. const_iterator does not have an operator[].
    [color=blue]
    > How can I access the node like as if it were a myvec (by reference is
    > nice if that is OK).[/color]

    Try (*x)[i].

    --
    Marcus Kwok

    Comment

    Working...