In c++ there is only virtual destructors, no constructors. Why?
Answer Posted / bala preethi
Since OOPS basics says always base class object to be
created and than its derivatives. So just consider the case
where we try to create object of derived class with virtual
contructor since pointer points to derived type object it
fetches derived constructor directly, without its base
class object constructed( instantiated )...
So Constructor cannot be made virtual bt when comes to case
of Destructor object destuction process must be reverse...
So we must make destructor as virtual.
This applies only when we going for Dynamic Memory
Allocation...
If, on the other hand, you were to have a pointer to object
A and assign it a dynamic object B, when you destroy it,
only object A's destructor is called and object B part of
the object is never destroyed. Virtual destructors are used
to solve this problem and destroy the objects in the right
order.
| Is This Answer Correct ? | 47 Yes | 14 No |
Post New Answer View All Answers
Is this job good for future? can do this job post grduate student?
What are the benefits of polymorphism?
How is class defined?
What is the point of oop?
What is encapsulation c#?
What is variable example?
What is abstraction and encapsulation?
how to get the oracle certification? send me the answer
Is enum a class?
What is polymorphism and types?
What does sksksk mean in text slang?
What is abstract class in oops?
What is encapsulation example?
What is difference between data abstraction and encapsulation?
How oops is better than procedural?