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

What is the real time example of inheritance?

649


What is pointer in oop?

543


Why it is called runtime polymorphism?

581


What are the features of oop?

643


What is inheritance write a program to show use of inheritance?

620






Why interface is used?

557


What is the difference between encapsulation and polymorphism?

602


What is overriding in oop?

554


Can you explain polymorphism?

585


Can enum be null?

592


What is the difference between procedural programming and oops?

565


What is ambiguity in inheritance?

629


what is difference between class template and template class?

2165


What is meant by multiple inheritance?

744


What exactly is polymorphism?

614