Dereferencing a null pointer usually ends up in an access violation - you either try to read from or write to the guard page, which stops you (with a thump).
However, if you're not actually reading from / writing to that null pointer, you're OK.
Member functions in C++ aren't actually "part of" the objects you kick around - they're named as such, but they're just like regular functions - chunks of code in memory somewhere. How is it that you can call a function on some particular object? Because C++ passes a hidden parameter to your member functions - the 'this' pointer - which lets it know which object it's currently "part of."
So when you dereference a pointer to an object and call a regular, nonvirtual function on it, the compiler turns that call into a "push this, call fn" setup. The function itself is well defined and exists in memory, always. The thing that's actually null is the 'this' pointer.
Which means that you should be able to catch some dereferencing-a-null-pointer errors like so:
assert(this, "Tried to call SomeFunction() on a NULL SomeObject!");
Possibly more usefully:
if(!this) return DEFAULT_VALUE;
It's filthy and disgusting and I love it. It can make some of those multiple levels of indirection easier to handle:
Object* pxObject = GetObject();
OtherObj* pxOtherObj = pxObject->GetOtherObject();
can become this:
if Object::GetOtherObject and OtherObj::DoWork can handle this being == NULL.
It won't work on virtual functions. Virtual functions are called by dereferencing 'this' (which dies) to look up the function address in the vtable. If the function is virtual it will die before it gets a chance to check the value of 'this'.
Washu and/or muer and/or Fruny are going to kill me.