I guess it is because p has 2 memory parts, 1 is for member functions, the other is for data. The assignment (p=0) only affects the part reserved for data. So by right it still works normally if we access the other part (p->print()).
Am I right or is it the compiler is just so smart that it altered the object?
Hi hamsterman,
I have tried both the was , what mancs is descussing about and what you are descussing about . But both seems working with out the crash .
I am not able to get that .. can any one of you explain that ?
I wouldn't call it refactoring. There is just one way to represent a function (sort of. you may want to google "calling conventions"). I only meant that the compiled code is (nearly) the same. The compiler does not transform methods to global functions.
As for learning, I can't say. Just ask here when you see something you don't know. Eventually some things will become apparent. Learning assembly might help some.
Member functions always implicity pass the calling object as the this pointer. The program doesn't crash because you aren't using the this pointer. That's it.
Note that this might crash or do weird things (if, for example, the function you are trying to call is virtual), so I don't recommend you ever think you can do it. Technically the language prohibits it.