title: Returning an object pointer from a recursive function met with access violation
body: <p>I've created a simple recursive function that performs preorder traversal to return a node that matches a target string.</p>
  <pre><code>#include &lt;bits/stdc++.h&gt;
  using namespace std;
  
  class Node {
      public:
      string value;
      Node *left, *right;
  
      Node(string value) {
          this-&gt;value = value;
          this-&gt;left = NULL;
          this-&gt;right = NULL;
      }
  };
  
  class Tree {
      public:
      Node* preorder(Node* root, string target) {
          if (root == NULL) return NULL;
  
          if (root-&gt;value == target) {
              return root;
          }
  
          preorder(root-&gt;left, target);
          preorder(root-&gt;right, target);
      }
  };
  
  int main() {
      Node* a = new Node(&quot;a&quot;);
      Node* b = new Node(&quot;b&quot;);
      Node* c = new Node(&quot;c&quot;);
      Node* d = new Node(&quot;d&quot;);
  
      a-&gt;left = b;
      a-&gt;right = c;
      c-&gt;left = d;
  
      Tree t = Tree();
      Node* found = t.preorder(a, &quot;d&quot;);
      cout &lt;&lt; found-&gt;value &lt;&lt; endl;
  }
  </code></pre>
  <p>The traversal is done correctly, but the program doesn't print anything. I just get a <code>[Done] exited with code=3221225477 in 2.038 seconds</code> after compiling with g++ and running.</p>
  <p>Where did I mess up with the pointers?</p>