LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


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

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


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

Thanks.

Last edited by kornerr; 08-23-2006 at 05:31 AM.
 
Old 08-23-2006, 06:21 AM   #2
cupubboy
Member
 
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
xhi
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!
 
  


Reply



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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:39 PM.

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