top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

C++: Why destructor is defined as virtual in a derived class ?

+1 vote
583 views
C++: Why destructor is defined as virtual in a derived class ?
posted Oct 1, 2018 by Vikram Singh

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button LinkedIn Share Button
I think it should be base class ?

In case, the derived class object ( accessed via the pointer to base class) is deleted, will result in undefined behaviour. (if the base destructor is not virtual). To avoid this, the base class destructor is made virtual.
Yeah , I agree with you. I believe that the query is related to destructor in base class.

Similar Questions
0 votes

What is a pure virtual destructor in C++? What is its need, advantage and disadvantage, please explain with example?

+2 votes

When a function is declared as virtual and when a class ? Please explain with examples.

...