#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    5
    Rep Power
    0

    STL list iterator issue


    I know that in the stl list iterator, the * operator returns the current element it's on. My question is, how can I actually output the data inside that element?

    It won't let me use the . or -> operator... Is this even possible?

    I need to be able to access the data in the current Element of the list to compare it with the values passed in and continue building my graph class :D

    Code:
    template <typename V, typename E>
    void Graph<V, E>::InsertEdge(V from, V to, E edge)
    {
    	std::list<Vertex<V>*>::iterator iter; //linked list of Vertex pointers
    	
    	for(iter = m_Vertices.begin(); iter != m_Vertices.end(); ++iter)
    	{
    		cout << (*iter).m_Data << endl;  //error here
    	}
    }
    Any help is highly appreciated, thanks
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2009
    Posts
    45
    Rep Power
    7
    typename keyword is required:
    Code:
    typename std::list<Vertex<V>*>::iterator iter; //linked list of Vertex pointers
    If you don't understand iterators and pointers split your instruction into more lines to make the conversions more explicit:
    Code:
    Vertex<V> *Vertex_pointer = *iter;
    cout << Vertex_pointer->m_Data << endl;

IMN logo majestic logo threadwatch logo seochat tools logo