what is virtual destructor

Answer Posted / pankajkolte

Virtual Destructor is used basically to ensure proper the
sequence of call to destructor.

class Employee {
virtual ~Employee() {}
};

class Manager : public Employee {
~Manager() {}
}

Employee * m = new Manager();//here was the mistake
delete m; // <-

In this case base class destructor if marked as virtual so
as derived class destructor will get called first then base
class destructor.

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Write a c++ program to display pass and fail for three student using static member function

2810


What is interface in oop?

658


Why is static class not inherited?

591


What is the real time example of encapsulation?

591


Why oops is important?

603






Why is oop useful?

600


Can an interface inherit a class?

557


What is use of overloading?

604


What is the use of oops?

617


What is overloading in oops?

596


What are the 3 pillars of oop?

611


Why do we need oop?

661


How to hide the base class functionality in Inheritance?

636


Which is not an object oriented programming language?

537


Why multiple inheritance is not allowed?

581