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 do we need polymorphism in c#?
What are the types of abstraction?
what is the 3 types of system development life cycle
What is interface in oop?
What is difference between data abstraction and encapsulation?
What does <> mean pseudocode?
What are the benefits of oop?
What is encapsulation in simple terms?
Can bst contain duplicates?
What is encapsulation c#?
hi, this is raju,iam studying b.tech 2nd year,iam want know about group1 and group2 details, and we can studying without going to any instutions? please help me.
What is abstract class in oops?
What is abstraction encapsulation?
Why is static class not inherited?
What is the main purpose of inheritance law?