I have an array of pointers to a structure called "table" (the structure is called Node).
I declare the array as so in the class:
Node * table;
Then, in another method, I initalize the table:
this->table = new Node [this->length];
And everything works fine. this->length is a valid entry, this->table is pointing to the right array, and etc. However, then I try to change the value of the elements:
for(int i = 0; i < this->length; i++) {
this->table[i] = new Node;
}
Or even
for(int i = 0; i < this->length; i++) {
this->table[i] = 0;
}
And everything starts bugging out. Why can't I set these pointers to anything?
This is the error I get:
(Where line 15 is the line of "this->table[i] = new Node;").
I hate to post long segments of code, so here's a shortened version of the code itself:
template <class T, class S>
class HashMap {
public:
HashMap();
private:
struct Node;
Node * table;
static const unsigned length = 100;
};
template <class T, class S>
HashMap<T, S>::HashMap() {
this->table = new Node [HashMap::length];
for(int i = 0; i < HashMap::length; i++) {
this->table[i] = new Node;
}
}
template <class T, class S>
struct HashMap<T, S>::Node {
T value;
S key;
Node * next;
};
No research I'm doing is telling me what the error is; any help is appreciated!