would you please tell me why the destructors for the objects that pJ and pK are pointing were not called? I am sure there is a very simple answer for that.. but I just can't get it. help!
Include delete pJ and delete pK at the end of your code. Read the documentation for keywords new and delete. The memory created using the operator new must be explicitly deallocated. Since the objects *pJ and *pK are never destroyed by the code, the desctructors are never called.
There are two reasons that your destructors aren't being called, one is as kishor8dm pointed out that you are using the operator "new" and because of that the "delete" command must be called explicitly.
The other is because the objects are inside of your main() function and as such their scope is the same as the program itself. If these were part of a function (and the "new" operator was not being used) then their destructors would be called at the end of that functions life.
well, I was waiting for my train, and all of a sudden, asked myself "why did you left the pointers behind?" :) I think I'm going crazy. you're right, they should be deleted. I could also call destructors explicitly I guess, which is really unnecessary.
BUT, I don't know about the scope issue, because when the objects are in the stack, and the program is over, everything is cleared up. that's truly my weak pointer/free store knowledge..
Thanks a lot for your replies.
I thought I caught that in time. I have never called a destructor explicitly until now, I honestly didn't think you could. What bothers me is that I can still reference it even after the destructor is called.
/*
pJ: cFirstConstr@ 0x1fd6010
pK: cFirstConstr@ 0x1fd6030
cSecondConstr@ 0x1fd6030
L: cFirstConstr@ 0x7fff90f12590
M :cFirstConstr@ 0x7fff90f12580
cSecondConstr@ 0x7fff90f12580
O :cFirstConstr@ 0x7fff90f12570
cFirstDestr@ 0x1fd6010 --> object that pJ was pointing is killed
cSecondDestr@ 0x1fd6030 --> the one pK was pointing is killed (derived part)
cFirstDestr@ 0x1fd6030 --> base part of the same above (pK) is killed
cFirstDestr@ 0x7fff90f12570 --> O is gone
cSecondDestr@ 0x7fff90f12580 --> derived part of M is gone
cFirstDestr@ 0x7fff90f12580 --> base part of M is gone
cFirstDestr@ 0x7fff90f12590 --> L is gone
*/