View Single Post
  #10  
Old 08-24-2014, 22:19
tonyweb tonyweb is offline
Family
 
Join Date: Jan 2009
Posts: 190
Rept. Given: 190
Rept. Rcvd 95 Times in 36 Posts
Thanks Given: 1,910
Thanks Rcvd at 299 Times in 122 Posts
tonyweb Reputation: 95
Quote:
Originally Posted by BlackWhite View Post
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 View Post
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 View Post
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
__________________
Want to learn unpacking ... but I'm too stupid

Last edited by tonyweb; 08-24-2014 at 22:28.
Reply With Quote