title: segfault to a null pointer C++
body: <pre><code>WordBinaryTree::WordBinaryTree()
  {
     //RootNode is a private WordNode* of WordBinaryTree()
     RootNode = 0; //just to set it to null...
  }
  
  void WordBinaryTree::AddNode(WordNode node)
  {
    //RootNode is WordNode*, should be null the first time through
    WordNode* currNode = RootNode;
  
    if (!currNode)
    {
       currNode = new WordNode();
       currNode-&gt;Value = node.Value;
       currNode-&gt;Word = node.Word;
       RootNode = currNode;
       return;
    }
  
    while (1)
    {
       if (currNode-&gt;Value &gt; node.Value) 
       //other code here......
  </code></pre>
  
  <p>I'm not quite sure what in the world is wrong with my code. I've searched online and nothing is coming up with a solution. WordNode is a type struct and RootNode is simply a pointer to that. I never set new to RootNode, so it's simply a null pointer the first time this runs through. However, when I try to check if it's null (via currNode), it keeps coming up false and saying it's not null. Therefore, that first if statement never goes through. This causes a segfault when the if statement in the while loop happens because it's trying to get a value from a null pointer.</p>
  
  <p>Why is this happening? I tried valgrind but it just tells me that there's no malloc/free/etc. via the address where RootNode is at. I know that! I'm trying to make a new if it's null (via that if statement) but it just keeps coming up as false, as if the RootNode isn't really null. So what do I do?</p>