Hi all,
I am unable to detect the error in the following C++ program. The code defines a Graph class.
#include <vector>
#include <list>
using namespace std;
class Neighbor {
public:
int node_id;
float edge_cost;
float price;
Neighbor(int&,float&,float&);
};
Neighbor::Neighbor(int& node_id, float& edge_cost,float& price) {
this->node_id = node_id;
this->edge_cost = edge_cost;
this->price = price;
}
template <class NS>
class Graph {
private:
vector<list<NS> > adjacency_list;
vector<list<NS> >::iterator node_iterator;
public:
void add(int node_id, Neighbor& neighbor);
void remove(int node_id, Neighbor& neighbor);
Graph();
};
template <class NS>
Graph<NS>::Graph() {
node_iterator = adjacency_list.begin();
}
template <class NS>
void Graph<NS>::add(int node_id, Neighbor& neighbor) {
if(adjacency_list.size()<node_id){
while(adjacency_list.size()<node_id)
adjacency_list.pushback(list<NS>());
}
adjacency_list[node_id].push_back(neighbor);
}
template <class NS>
void Graph<NS>::remove(int node_id,Neighbor& neighbor) {
if(adjacency_list.size()<node_id)
return;
adjacency_list[node_id].remove(neighbor);
}
When I compile it, I get the following error:
max_flow.cpp:21: error: type ‘std::vector >, std::allocator > > >’ is not derived from type ‘Graph’ max_flow.cpp:21: error: expected ‘;’ before ‘node_iterator’ max_flow.cpp: In constructor ‘Graph::Graph()’: max_flow.cpp:31: error: ‘node_iterator’ was not declared in this scope
vector::iterator works. But why doesn't vector >::iterator ?
Thanks!