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?
1 2 3 4 5 6 7 8 9 10
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; //How do I display the data in iter?
}
}
Peter87 is right, though I wonder if this is just a mix-up since you have a container of pointers. *iter returns a pointer which you did not dereference, explaining why (*iter).m_Data and iter->m_Data do not work. In reality, the call to the member should be (*(*iter)).m_Data or the more readable (*iter)->m_Data.