title: Accessing class members on a NULL pointer
body: <p>I was experimenting with C++ and found the below code as very strange. </p>
  
  <pre><code>class Foo{
  public:
      virtual void say_virtual_hi(){
          std::cout &lt;&lt; "Virtual Hi";
      }
  
      void say_hi()
      {
          std::cout &lt;&lt; "Hi";
      }
  };
  
  int main(int argc, char** argv)
  {
      Foo* foo = 0;
      foo-&gt;say_hi(); // works well
      foo-&gt;say_virtual_hi(); // will crash the app
      return 0;
  }
  </code></pre>
  
  <p>I know that the virtual method call crashes because it requires a vtable lookup and can only work with valid objects. </p>
  
  <p>I have the following questions </p>
  
  <ol>
  <li>How does the non virtual method <code>say_hi</code> work on a NULL pointer?</li>
  <li>Where does the object <code>foo</code> get allocated?</li>
  </ol>
  
  <p>Any thoughts?</p>