By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,159 Members | 913 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,159 IT Pros & Developers. It's quick & easy.

Base classes destructors

P: n/a
Cn someone tell me if when i call the destructor of a derivated class,
the destructor of the base class is called implicitly?

Or shall i call the destructor by myself?

Thanks in advance

Nuno Barros
Jul 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

Cn someone tell me if when i call the destructor of a derivated class,
the destructor of the base class is called implicitly?

Or shall i call the destructor by myself?

The base destructor will be called implicitly after the derived constructor
completes; you don't have to call it.
Jul 19 '05 #2

P: n/a

"Nuno Barros" <nu*********@fc.ul.pt> wrote in message news:a8**************************@posting.google.c om...
Cn someone tell me if when i call the destructor of a derivated class,
the destructor of the base class is called implicitly?


Destructors for the base classes and member objects are called automatically
(after the destructor body of the derived class is run).
Jul 19 '05 #3

P: n/a
Buster Copley wrote:
Nuno Barros wrote:
Cn someone tell me if when i call the destructor of a derivated class,
the destructor of the base class is called implicitly?

Or shall i call the destructor by myself?

Thanks in advance

Nuno Barros

Provided the destructor is declared virtual in the base class, the less-
derived classes' destructors will be invoked when the more-derived
classes' destructors are completed.


I should have paused for thought, I've got it all backwards. Virtual
destructors are for deleting derived-class objects through base-class
pointers. The other posts are correct. Sorry!
Good luck,
Buster.


Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.