Calling a member function on a NULL pointer is cause for undefined behavior.
Your run time environment is dealing with the NULL pointer leniently. The call to testA()
does not cause any problems since you are not accessing any member variables. The call to testB()
crashes since you are trying to access a member variable when this
is NULL.
Conceptually, a member function is mapped to a function that has the form:
mangled_testA(Test* this){ ... }
If you call such a function on a NULL pointer, the function gets called with the value of this
set to NULL. If you don't access any member variables, you don't notice the error. If you access any member variables, you notice the error right away.
P.S. this behavior is not guaranteed by the language. This is what happens often.