Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 08-23-2006, 05:29 AM   #1
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Rep: Reputation: 35
Does derivated class inherit base class destructor (constructor)?

I have:
class A {
        ~A ();
class B: public A {
        void SomeFunc ();
Is it true that upon B destruction it automatically calls ~A () destructor (or somehow inherits it), or should I do:
B::~B () {
    A::~A ();


Last edited by kornerr; 08-23-2006 at 05:31 AM.
Old 08-23-2006, 06:21 AM   #2
Registered: May 2003
Location: Bucharest,Romania
Distribution: Fedora Core 7
Posts: 109

Rep: Reputation: 15
A's destructor will be invoked automatically
Old 08-23-2006, 08:05 AM   #3
Senior Member
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
there is no need to explicity invoke the destructor.. you do need to make the base class destructor virtual. if you inherit from a class, that base class needs to have a virtual destructor.. ALWAYS, otherwise bad things will follow!


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
In C++, how to write destructor of derived class? ArthurHuang Programming 3 06-04-2006 10:40 PM
fopen fclose in class constructor bedoni Programming 9 03-26-2006 10:25 AM
Undefined references to vtable in class constructor? RavenOfOdin Programming 2 03-01-2006 05:46 PM
c++ : regarding (inheritence)base class and derived class edreddy Programming 6 07-31-2002 06:33 PM
Class constructor not being called ChimpFace9000 Programming 1 06-03-2002 08:54 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:45 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration