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 the difference between encapsulation and polymorphism?
What is data binding in oops?
What are the benefits of interface?
What is cohesion in oop?
design a c++ class for the chess board,provide a c++ class definition for such class(only class definition is required)
What is coupling in oop?
What is interface in oop?
Write a program to sort the number with different sorts in one program ??
Why do we use oop?
What is protected in oop?
Write a program to implement OOPS concepts such as inheritance, polymorphism, friend function, operator overloading?
Why is oop useful?
What are classes oop?
String = "C++ is an object oriented programming language.An imp feature of oops is classes and objects".Write a pgm to count the repeated words from this scenario?
What is coupling in oops?