Ok, here is my thinking. I need myNodePool to be accessible everywhere, just like my bst tree. But i want myNodePool to "inside" of bst, i.e. if I have a var "bst tree" then to access myNodePool it would look something like this: tree.myNodePool[val].var. So I added "NodePool myNodePool" under the public definitions in bst.h - so do I have to do anything else with myNodePool inside of bst.cpp? Just by declaring it in bst.h should it call the default constructor for NodePool, correct?
I've added this code to node.cpp:
Code:
Node NodePool::operator[] (int indx)
{
char errStr[99];
if (indx >= SIZE || indx < 0)
{
sprintf(errStr, "%s %d: Index %d not in range 0 to %d", __FILE__, __LINE__, indx, SIZE);
throw range_error(errStr);
}
if (!pool[indx].used)
{
sprintf(errStr, "%s %d: Index %d refers to a node on the freelist.", __FILE__, __LINE__, indx);
throw range_error(errStr);
}
return pool[indx];
}
And: (node.h)
Code:
class NodePool
{
...
public:
NodePool(void);
Node operator[](int indx);
...
I think that I am getting myself really confused. When I asked my professor "Now would the default bst constructor be the one to create the new NodePool object?" he replied "Yes". However that just creates a local variable.
Now when I compile I am only getting this error:
Code:
37 bst.cpp expected primary-expression before "void"
Code excerpt:
Code:
int bst::insert (string word, int lineno)
{
// Check to see if the string is already in the BST
int duplicate;
duplicate = search(word);
if(duplicate == -1)
{
// No duplicate found, get next available node
next = myNodePool.get(void); // line 37
myNodePool[next].value = word;
myNodePool[next].lineNumber = lineno;
myNodePool[next].used = true;
return 0;
}
else
return -1;
}