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
Why multiple inheritance is not allowed?
What is an advantage of polymorphism?
write a program that takes input in digits and display the result in words from 1 to 1000
What are main features of oop?
Can we override main method?
hi all..i want to know oops concepts clearly can any1 explain??
What is the significance of classes in oop?
What are the components of marker interface?
INSTANCE FIELDS DECLARED private ARE ACCESSIBLE BY THE METHODS ONLY.CAN WE CHANGE THE private FIELD OF AN OBJECT IN A METHOD OF SOME OTHER OBJECT OF THE SAME CLASS?
can we make game by using c
What are oops functions?
What is destructor give example?
Can you inherit a private class?
What is difference between pop and oop?
What is encapsulation in oop?