Hi all.
I am trying to build a Binary Linked Trie but fail in basic pointer operations.Following code can be built but in debug or run mode, it breaks and outputs the error.
typedef struct node
{
char ch;
node *next;
};
struct node *root = NULL;
void add(struct node *leaf, char ch)
{
leaf = new node;
leaf->ch = ch;
leaf->next = NULL;
}
void read()
{
while(root->next != NULL)
cout << root->ch;
}
int _tmain(int argc, _TCHAR* argv[])
{
struct node *conductor;
add(root, 'a');
conductor->ch = 'l';
conductor->next = NULL;
root->next = conductor;
read();
return 0;
}
The error is "CXX0030, Expression Cannot Be Evaluated."
In step mode of debug, conductor is looks like this in Autos "{ch=???, next=???}".
It looks like a mistake about pointer arytmetichs,but I can't see it. I guess it says me "I don't know what is root->next".
By the way these are the other instructions:
Visual Studio 2010
Visual C++
Win32 Console Application
#include <iostream>
using namespace std; and not using another header file.
Thanks.