I am using a vector of pointers to create a data structure and find that I am getting an error that seems unclear. Here is the basic 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 am receiving on 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 have tried removing the for loop and simply attempted to declare the iterator and get the scope error. My searches have shown that usually this is attributed to a missed semicolon at the end of the inner class or the lack of public being in the inner class, but this is not the case. Is there a special declaration necessary for an iterator of a vector of pointers?