I use a pointer vector to create a data structure and find that I am getting an error that seems obscure. Here is the base code from the header file
#include <vector> using namespace std; template <typename Key, typename Value> class ST{ class STNode{ public: STNode(Key k, Value v) : key(k), value(v){} ~STNode(){} Key key; Value value; }; typedef typename ST<Key, Value>::STNode Node; public: ST():v(NULL) {v = new vector<Node*>();} ~ST(){ // vector contains allocated objects for(vector<Node*>::iterator it = v->begin(); it != v->end(); ++it) delete (*it); delete v; } private: vector<Node*>* v; };
The error message I get in g ++ version 4.6.6 is
ST.h: In destructor 'ST<Key, Value>::~ST()': ST.h:20: error: expected ';' before 'it' ST.h:20: error 'it' was not declared in this scope
I tried removing the for loop and just tried declaring an iterator and getting a scope error. My searches have shown that this is usually due to a missing semicolon at the end of the inner class or a lack of public presence in the inner class, but this is not so. Is there a special declaration for a pointer vector iterator?
source share