When I run my program, following error occurs each time when I use temp->
.
[Error] request for member 'key' in '* temp', which is of pointer type 'NodeType {aka Node*}' (maybe you meant to use '->' ?)
What is wrong with the code.
struct Node;
typedef Node *NodeType;
int NumNodes = 0;
const int SIZE = 100;
NodeType data[SIZE];
struct Node{
int key;
NodeType *left, *right;
};
NodeType *newNode(int value){
if(NumNodes == SIZE)
cout << "This Node Pool is full." << endl;
exit(1);
NodeType *temp = &data[NumNodes++];
temp->key = value;
temp->left = temp->right = NULL;
return temp;
}
typedef
-ing pointers (like you did forNodeType
). It makes your code unreadable. Explicitly codeNode*
when needed. BTW, your error happens when you compile your program. Do enable all warnings and debug info when compiling (e.g.g++ -Wall -Wextra -g
with GCC). Learn to compile on the command line. Read How to debug small programs – Basile Starynkevitchtypedef
it gives an error NodeType does not name a type – muzziNodeType
withNode*
and then remove the typedef .... – 463035818_is_not_a_numberNode
– muzzi