Quote:
Originally Posted by BlackWhite
If I create a class say MyClass which inherits CWin, and assume
that ~MyClass() will be automatically called when the MyClass object is deleted,
|
This is a good assumption given that you inherited "correctly" (see later).
Quote:
Originally Posted by BlackWhite
then I can decide whether to transfer control to ~CWin() in
~MyClass().
|
As deepzero wrote, both ~MyClass() and ~CWin() will be called because of the hierarchy you established between the two classes.
Quote:
Originally Posted by BlackWhite
But the weird situation is that ~CWin() is called instead of
~MyClass() when the MyClass object is deleted.
|
And, maybe, here's what you're missing (if I understood you correctly)! The destructor of the base class MUST BE virtual if you're destroying the object of the derived class through a pointer of the base class type.
cfr. http://stackoverflow.com/questions/461203/when-to-use-virtual-destructors
Hope this helps a bit
Regards,
Tony