title: Root node should have an assigned node, but remains NULL. Why can't I assign a node to my root?
body: <p>I'm writing a binary tree in object-oriented format. I've had experience with binary trees before, but it's been a while since I've touched on this. My problem is that I'm unable to assign a node to my root. Every time I check in debugging mode, the root remains NULL. While this is happening, the cur node contains all the information it's assigned.</p>
  
  <p>I've tried making my root private and changing <code>this-&gt;root = NULL;</code> to <code>root-&gt; = NULL;</code>. I've also tried making all of my functions public, but it didn't make a difference. I tried declaring root's children to NULL values and name to an empty string as well.</p>
  
  <p><strong>main.cpp</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;fstream&gt;
  #include "Friends.h"
  
  using namespace std;
  
  int main() {
      string line;
      ifstream file;
      file.open("friends.txt");
  
      Friends f;
  
      while (getline(file, line)) {
          f.insert(f.root, line);
      }
      f.print(f.root);
  
      system("pause");
      return 0;
  }
  </code></pre>
  
  <p><strong>Friends.cpp</strong></p>
  
  <pre><code>#include "Friends.h"
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  Friends::Friends() {
      this-&gt;root = NULL;
  }
  
  Friends::node* Friends::createNode(string&amp; val) {
      node* newNode = new node();
      newNode-&gt;left = NULL;
      newNode-&gt;right = NULL;
      newNode-&gt;name = val;
      return newNode;
  }
  
  Friends::node* Friends::insert(node* cur, string&amp; val) {
      if (!cur) {
          cur = createNode(val);
      }
      else if (val &lt; cur-&gt;name) {
          insert(cur-&gt;left, val);
          return cur;
      }
      else if (val &gt; cur-&gt;name) {
          insert(cur-&gt;right, val);
          return cur;
      }
      return NULL;
  }
  
  void Friends::print(node* cur) {
      if (!cur) {
          return;
      }
      print(cur-&gt;left);
      cout &lt;&lt; cur-&gt;name &lt;&lt; endl;
      print(cur-&gt;right);
  }
  </code></pre>
  
  <p><strong>Friends.h</strong></p>
  
  <pre><code>#ifndef FRIENDS_H
  #define FRIENDS_H
  
  #include &lt;string&gt;
  
  using namespace std;
  
  class Friends {
  private:
      struct node {
          string name;
          node* left;
          node* right;
      };
  public:
      node* root;
      node* insert(node* cur, string&amp;);
      void print(node* cur);
      Friends();
      node* createNode(string&amp;);
  };
  
  #endif
  </code></pre>
  
  <p>The root node should have a node, but has keeps showing up as a <code>NULL</code> value. It doesn't run with any errors either. It just remains as <code>NULL</code>.</p>