problem passing list iterator

V

vfunc

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.
 
K

Kai-Uwe Bux

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
 
V

vfunc

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..."
 
V

vfunc

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top