473,386 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

Mar 16 '06 #1
3 2349
vf***@talktalk.net 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[i]
Try:

(*x)[i]

or

x->operator[](i)

or, if you want range checking

x->at(i)
};

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

Mar 16 '06 #2
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 '06 #3

vf***@talktalk.net 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 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: darkstorm | last post by:
Hi, Please have a look at this code when compiling it is giving error: error C2440: '=' : cannot convert from 'ListNode *' to 'List<T>::ListNode *' with when I added List<T>:: before...
1
by: darkstorm | last post by:
Please check this program...When I compiles it in VC.net, it gives the following error: =============== Common\Lib\PList.h(115): error C2440: '=' : cannot convert from 'ListNode *' to...
13
by: Adam Hartshorne | last post by:
Hi All, I was wondering if anybody can tell me what is wrong with the following code, in a .h file I have std::list<std::vector<Site> > positions ; std::list<std::vector<Site> >::iterator...
2
by: weatherman | last post by:
Dear all, When porting some code from g++ 2.95/3.2 to g++ 4.01 we encountered some difficulties with the following construction. The code is known to compile on g++ 2.95 and g++ 3.2.2. This...
3
by: Mark P | last post by:
I'm having a problem compiling some template code. Here's a seemingly useless block of code which I've stripped down to illustrate my problem. Why is the second call to a.foo not accepted by the...
17
by: Ashwin | last post by:
hi guys, i have overloaded the << operator.as shown below. ostream& operator<<(ostream &out, const student &a) { out<<a.idno; out<< " " ; // out<< a.name; out<< " " ; // out<< a.marks...
15
by: jayesah | last post by:
Hi All, List and its iterator work as following way : list<intmylist; list<int>::iterator itr; itr = mylist.begin(); cout << (*itr); But I want something like this:
15
by: fungus | last post by:
I'm moving some code from VC++ 6 to VC++ 2005 and I've run into a nasty problem because iterators are no longer pointers. In the program I'm moving, there's a std::vector of items hidden inside...
18
by: desktop | last post by:
1) I have this code: std::list<intmylist; mylist.push_back(1); mylist.push_back(2); mylist.push_back(3); mylist.push_back(4);
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.