LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Does derivated class inherit base class destructor (constructor)? (https://www.linuxquestions.org/questions/programming-9/does-derivated-class-inherit-base-class-destructor-constructor-476521/)

kornerr 08-23-2006 05:29 AM

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.

cupubboy 08-23-2006 06:21 AM

A's destructor will be invoked automatically

xhi 08-23-2006 08:05 AM

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!


All times are GMT -5. The time now is 01:22 AM.