title: Checking for a null object in C++
body: <p>I've mostly only worked with C and am running into some unfamiliar issues in C++.</p>
  
  <p>Let's say that I have some function like this in C, which would be very typical:</p>
  
  <pre><code>int some_c_function(const char* var)
  {
      if (var == NULL) {
          /* Exit early so we don't dereference a null pointer */
      }
      /* The rest of the code */
  }
  </code></pre>
  
  <p>And let's say that I'm trying to write a similar function in C++:</p>
  
  <pre><code>int some_cpp_function(const some_object&amp; str)
  {
      if (str == NULL)  // This doesn't compile, probably because some_object doesn't overload the == operator
  
      if (&amp;str == NULL) // This compiles, but it doesn't work, and does this even mean anything?
  }
  </code></pre>
  
  <p>Basically, all I'm trying to do is to prevent the program from crashing when some_cpp_function() is called with NULL.</p>
  
  <ul>
  <li><p>What is the most typical/common way of doing this with an object C++ (that doesn't involve overloading the <code>==</code> operator)?</p></li>
  <li><p>Is this even the right approach? That is, should I not write functions that take an object as an argument, but rather, write member functions? (but even if so, please answer the original question)</p></li>
  <li><p>Between a function that takes a reference to an object, or a function that takes a C-style pointer to an object, are there reasons to choose one over the other?</p></li>
  </ul>