c++ - NULL pointer able to access class member function -
possible duplicate:
accessing class members on null pointer
a silly question or may conceptual doubt.
#include <iostream> using namespace std; class { public: void print() { cout<<"printing\n"; } }; int main() { * = null; a->print(); return 0; } the output is: printing
how a pointer(which null) able access member function of class a.
please explain... may silly question had impression null pointer not access class's member function.
dereferencing null pointer, in code, undefined behavior. 1 of possibilities of such undefinedness may work. may crash next time, or totally unexpected.
since not using implicit this argument in member function print, seems such null pointer never needs actually dereferenced.
Comments
Post a Comment