templating iterator syntax error

I cant seem to find the correct syntax to point the iterator to the linked list. The G vector holds a vertex and a vertex has a linked list of edges. this makes up a graph, I can not change the Graph.h file (prof orders). I am trying to print out the contents of each Vectors name and its linked list name and weight. I know I will need this syntax for later functions.
[template <class V, class W> // V is the vertex class; W is edge weight class

struct edgeRep
{
V name; // Vertex name
W weight; // Edge weight
};

template <class V, class W>
struct vertex // Array cell structure for graph
{
typedef edgeRep<V,W> edge;
V name; // Vertex name
int visited; // Used during traversal, Breadth-First or Depth-First
list<edge> edgelist; // Pointer to edge list
};

template <class V, class W>
class Graph
{
protected:// protected member functions
std::vector< vertex<V,W> > G;// Main graph array for adjacency list representation
public:
//other functions....

};
/*****
NOTE:i did get this other function, working and i can see that the variables are in there
******/
template <typename V, typename W> //templated boilerplate
void Graph<V,W>::GetGraph()
{
ifstream inF;
char g;//garbage
string filename;//change to templated V name later
int weight;//change to templated W name later
vertex<V,W> city;//temp vector to add citys
edgeRep<V,W> path;//temp path to add adj citys

//ask for graph textfile
cout<<"Enter the fully qualified file path including\n"
<<"file name for the Graph: ";
cin>>filename;

inF.open(filename.c_str());
while (!inF.eof())
{
city.name = "";
inF >> g;
while(g != ' ')
{
city.name += g;
inF.get(g);
}
cout << "new city is: " << city.name << endl;
do
{
inF >> g;
if(g != '#')
{

while(g != ' ')
{
path.name += g;
inF.get(g);
}
inF >> path.weight;
cout << "adding adj city: " << path.name << " , " << path.weight << endl;
city.edgelist.push_back(path);
path.name = "";
}
} while(g != '#');
G.push_back(city);//add city and adj list to vector
cout << endl << endl;
inF.get(g);
if(inF.peek() == inF.eof())
inF.get(g);
}
inF.close();

}


[template <typename V, typename W> //templated boilerplate
void Graph<V,W>::SimplePrintGraph()
{
unsigned i = 0;
V init = G[i].name;
G.shrink_to_fit();
while( i < G.size())
{//how do i print the starting (init) name and all the adj names and weights from the LL
for(G[i].edgelist::iterator it = this->begin(); it != end(); it++)
{
cout << "<" << init << " , " << it->name << " , " << it->weight << "> " << endl;
}
i++;
init = G[i].name;
}//cout << "<" << G[i].name << " , " << G[i].edgelist.name << " , " << G[i].edgelist.weight << "> " << endl;

}
Last edited on
Topic archived. No new replies allowed.