First of all, memberFunction() prints out its parameter, not the value of m_memberVariableX (which also happens to be "assigned" 10 in the constructor), so there is no magic as to why 10 is printed. But the real question is why does the program not crash. You have to understand how the compiler handles member functions.
Although the prototype for memberFunction is
|
void memberFunction( int arg_param )
| |
what really happens beneath the scenes is the compiler passes a second parameter to this function, that parameter being a pointer to the instance of A that you are calling the member function on. (The so-called "this" pointer, essentially). Because memberFunction doesn't actually look at any data members of A, the pointer is not derefenced; it is simply unused. This is why the code above does not crash. This also explains why it does crash if you attempt to print m_memberVariableX, because now you are attempting to dereference the "this" pointer to access the member variable.
You should find that another way to crash this program is to make memberFunction (as it is now) a virtual function. Even though it still doesn't access any data members, it still crashes.
Since I just answered your homework question, I'll leave the answer to my question for you to figure out.