In c++ there is only virtual destructors, no constructors. Why?
Answer Posted / subhashish sen
Constructor can not be virtual...The main reason is when we
have a virtual function in a class the VTABLE for that
function will be created..which contains the address of the
virtual function...means for each class which contains a
virtual function a VTABLE will be created and constructor is
an entity which initializes this VTABLE.So if you declare
constructor as virtual who will initialize VTABLE for it.
Destructors can be virtual because virtual destructor
ensures proper calling order of all destructors in a class
hierarchy.
If you need further clarification reply me....
| Is This Answer Correct ? | 28 Yes | 9 No |
Post New Answer View All Answers
What is overriding vs overloading?
what is the sylabus for priliminaries?
What is the difference between abstraction and polymorphism?
What causes polymorphism?
Why interface is used?
Where is pseudocode used?
What is Difeerence between List obj=new ArrayList(); and ArrayList obj=new ArrayList()?
What is the difference between static polymorphism and dynamic polymorphism?
Is oop better than procedural?
Can a destructor be called directly?
hi all..i want to know oops concepts clearly can any1 explain??
What is abstraction in oop with example?
Can you explain polymorphism?
Why is encapsulation used?
What does no cap mean?