By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,434 Members | 1,854 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,434 IT Pros & Developers. It's quick & easy.

graph using adjacency list - problem

P: 5
Here's my code that's supposed to be a basic graph implementation using adjacency lists. It comes straight from R.Sedgewick's "Algorithms in C++".
However "23 - ISO C++ forbids declaration of `vector' with no type ". Why is that?


Expand|Select|Wrap|Line Numbers
  1.  
  2. class graf
  3. {
  4.  
  5.     struct edge
  6. {
  7.        int v, w;
  8.        edge(int v = -1, int w = -1) : v(v), w(w) {}
  9. };
  10.  
  11. struct node
  12.               {
  13.                      int v; node* next;
  14.                      node(int x, node* t) {v = x; next = t; }
  15.               };
  16.  
  17.       typedef node* link;
  18.       vector <link> adj;
  19.  
  20.  
  21.  
  22. public:
  23.              graf(int V) : adj(V) {adj.assign(V,0);}
  24.              int insert(edge e)
  25.              {
  26.                  int v = e.v, w=e.w;
  27.                  adj[v] = new node(w, adj[v]);
  28.                  adj[w] = new node(v, adj[w]);
  29.                  } 
  30.              void remove(edge e);
  31.              bool edge(int v,int w) const;
  32.              class adjIterator;
  33.              friend class adjIterator;
  34. };
Nov 13 '08 #1
Share this Question
Share on Google+
2 Replies


boxfish
Expert 100+
P: 469
Do you have
Expand|Select|Wrap|Line Numbers
  1. #include <vector>
  2. using namespace std;
and the top of your header file?
Nov 13 '08 #2

P: 5
Do you have
Expand|Select|Wrap|Line Numbers
  1. #include <vector>
  2. using namespace std;
and the top of your header file?

I forgot about it... Thank you again!
Nov 13 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.