-
Thanks for the help! I have a new question now. When I run my program it unexpectantly ends - "This application has requested the runtime to terminate it in an unusual way". After putting in debugging statements I have found the root of this error to be whenever I call myNodePool[]. For example, here is the first occurance of myNodePool, in main.cpp:
Code:
int main(int argc, char *argv[])
{
ifstream fileStream;
char *fileName;
string line;
int lineNo;
bst tree;
[clip]
for(int ii = 0; ii < SIZE-1; ii++)
{
cout << "ii = " << ii << "\n";
cout << "checking Nodes...\n";
cout << "myNodePool[" << ii << "].left = " << tree.myNodePool[ii].left << "\n"; // terminates
cout << "myNodePool[" << ii << "].right = " << tree.myNodePool[ii].right << "\n";
}
My constructor for NodePool looks like:
Code:
NodePool::NodePool(void)
{
free = 0;
for(int ii = 0; ii < SIZE-1; ii++)
{
pool[ii].left = 2 * ii;
pool[ii].right = (2 * ii) + 1;
pool[ii].used = false;
}
pool[SIZE-1].left = -1;
pool[0].right = -1;
}
Which should populate all nodes (in my case 10,000) with appropriate integers as defined by 2ii and 2ii+1. I'm assuming that this constructor is never being called and thus when I try to use myNodePool, nothing is in it. In bst.h I call NodePool myNodePool:
Code:
using namespace std;
class bst
{
public:
bst(void);
bool empty(void);
int insert (string word, int lineno);
int search (string word);
void inorder (ostream & out);
string modifyWord(string ss);
NodePool myNodePool;
};
So shouldn't creating a new NodePool object automatically call the default NodePool constructor, thus populating my Node array?
-
Update: apparently the NodePool default constructor is being called and my node .left and .right values are being saved - I added a cerr output at the start of the method to print "NodePool Called" and sure enough that is the first thing that prints out, before my program terminates. So then why am I not able to call myNodePool? Any ideas?
-
What does the declaration of pool look like inside the NodePool class?