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
Explain the concepts involved in Object Oriented programming.
What is abstract class in oop?
How many human genes are polymorphic?
How do you define a class in oop?
What is a function in oop?
Why do we use polymorphism in oops?
Do you know about multiple inheritance?
What are oops methods?
What is the full form of oops?
Can main method override?
What are constructors in oop?
What is difference between data abstraction and encapsulation?
What is the oops and benefits of oops programming?
What is the real life example of polymorphism?
What is inheritance write a program to show use of inheritance?