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
IS IT NECESSARY TO INITIALIZE VARIABLE? WHAT IF THE INSTANCE VARIABLE IS DECLARED final ? IS IT NECESSARY TO INITIALIZE THE final VARIABLE AT THE TIME OF THEIR DECLARATION?
What is abstraction encapsulation?
What are benefits of oop?
#include
Why multiple inheritance is not possible?
Can we create object of interface?
Describe these concepts: Polymorphism, Inheritance and Abstraction.
What is the example of polymorphism?
What is cohesion in oop?
Why can't we have instance(stack) of a class as a member of the same class like eg.Class A{A obj;} as we can have self refential pointer
What is inheritance in oop?
What is basic concept of oop?
Plese get me a perfect C++ program for railway/airway reservation with all details.
What is encapsulation in ict?
What is polymorphism oop?