Salesforce Interview Question
Developer Program EngineersCountry: India
This question was recently discussed on the comp.lang.c++.moderated newsgroup. Since links are not allowed here you might add the 'http' by yourself:
groups.google.com/group/comp.lang.c++.moderated/browse_thread/thread/3ad55a2ae79c569c/
The basic reason why the above code works is as follows:
in C++ non virtual member function calls simliar to:
obj->functionName()
is expanded as
functionName(obj)
(remember the "this " pointer!!!? its the hidden first argument to all non-static member functions of a class.)
so now if u look at function call in given code, and the function expansion, its easy to see that it won't crash. Try making the function virtual or try accessing some member variables inside function. Then it will crash.
here show function not accessing any data... so no problem..
- Anonymous September 23, 2011if show function accessing some data of the class then it gives segmentation fault... because ob is null...