title: Checking for this == NULL in a member-function without invoking undefined behaviour
body: <p>Suppose I have a C++ class and I would like to have a recursive member-function which is called with instances items of the class,  for example</p>
  
  <pre><code>// the eplicit "this" is just for clarity in the following code:
  void recursivePrintTree(){
      (if this == NULL){ // We are "out" of the tree
          return; 
      }
      cout &lt;&lt; this-&gt;val;
      (this-&gt;leftSon)-&gt;printBinaryTree();
      (this-&gt;rightSon)-&gt;printBinaryTree();
  }
  </code></pre>
  
  <p>The problem is of course invoking undefined behaviour by calling printBinary with NULL in the first place! so I would like to avoid this, and as far as I know I have at least three ways of doing so:</p>
  
  <p>1) Using static member functions, which get an explicit this-type argument that can be safely checked. this is actually what I did so far but because it's a very recursive implementation, almost all of the member-functions get coded as static. That's not very good, right?</p>
  
  <p>2) checking the stop condition for the <em>next</em> node before having another recursive call with a NULL pointer possibly as "this". This is a much less natural form of writing and actually checks other items other that This. and I would like to avoid it.</p>
  
  <p>3) Using default dummy values. Tried it, felt it's not really saving me any special-case-treatment, but that may have been just because of the Generic-ness of my tree.</p>
  
  <p>I have really been fussing around this matter for a while now so would appreciate any good advice.</p>