New Reply

Problem with iterator for vector of lists in c++

 
Share Thread Thread Tools
Nov1-10, 05:54 PM   #1
 

Problem with iterator for vector of lists in c++


For a function

using namespace std;

mst(const vector<list<pair<int,int> > > &adj_lists, int v){
// code before iterator
list<pair<int,int> >:: iterator it;
it = adj_list[0].begin();
// code after
}

I'm trying to set up an iterator to walk through the list contained within adj_list[0], but the code above gives me a compiler error about there not being a match for "operator=". Am I wrong in believing that the vector should contain the starting point of the list? Thanks for any help.



*** hey everyone while waiting for responses I figured out the solution.
I should have been using

list<pair<int,int> >:: const_iterator it;

instead of

list<pair<int,int> >:: iterator it;

thanks to anyone who considered it.
PhysOrg.com
PhysOrg
science news on PhysOrg.com

>> Galaxies fed by funnels of fuel
>> The better to see you with: Scientists build record-setting metamaterial flat lens
>> Google eyes emerging markets networks
Nov1-10, 06:18 PM   #2
 
Recognitions:
Gold Membership Gold Member
Science Advisor Science Advisor
Retired Staff Staff Emeritus
Let's see.

adj_list is of type const vector<list<pair<int,int> > > &

Therefore, adj_list[0] is of type vector<list<pair<int,int> > >::const_reference, which ought to be of type const list<pair<int,int> > &.

Therefore, adj_list[0].begin() is of type list<pair<int,int> >::const_iterator

And since you generally cannot implicitly convert Container::const_iterator into Container::iterator, the compiler rightfully complains!
Nov1-10, 10:49 PM   #3
 
Ah, iterator vs const_iterator distinctions.

C++1x needs to hurry up so we can use "auto" already :(
New Reply

Tags
c++, iterator, lists, vector
Thread Tools


Similar Threads for: Problem with iterator for vector of lists in c++
Thread Forum Replies
vector iterator trouble (C++) Programming & Comp Sci 17
lists in mathematica Math & Science Software 4
Simple problem in Mathematica involving lists Math & Science Software 3
LinkedList Iterator Java tips Engineering, Comp Sci, & Technology Homework 2