Answer Posted / rock
When a derived class object pointed to by a base class
pointer dynamically is deleted only the base class
destructor is invoked inorder to even invoke derived class
destructor we use virtual destructor.
class shape
{
virtual ~shape(){}
};
class circle:public shape
{
~circle(){}
};
void main()
{
shape *sh = new circle;
delete sh; //both the destructors are invoked
}
If virtual keyword is not added to the base class
destructor only the base class destructor is called.
| Is This Answer Correct ? | 3 Yes | 0 No |
Post New Answer View All Answers
What are oops functions?
What are benefits of oop?
How to handle exception in c++, For example in a functions i am assigning memory to some variables and also in next instructions in am dividing one variable also. If this functions generates a error while allocating memory to those variable and also while dividing the variable if i divide by zero then catch block how it will identify that this error has cone from perticular instruction
What is object and class in oops?
what's the basic's in dot net
any one please tell me the purpose of operator overloading
How oops is better than procedural?
What is abstract class in oops?
What does no cap mean?
What is debug class?what is trace class? What differences are between them? With examples.
What are the benefits of polymorphism?
What causes polymorphism?
i am getting an of the type can not convert int to int *. to overcome this problem what we should do?
what is the drawback of classical methods in oops?
What is polymorphism and example?