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 an advantage of polymorphism?
Why interface is used?
what is the drawback of classical methods in oops?
Can a destructor be called directly?
Will I be able to get a picture in D drive to the c++ program? If so, help me out?
There are two base class B1,B2 and there is one class D which is derived from both classes, Explain the flow of calling constructors and destructors when an object of derived class is instantiated.
What is encapsulation and abstraction? How are they implemented in C++?
write a programe to calculate the simple intrest and compund intrest using by function overlading
assume the program must insert 4 elements from the key board and then do the following programs.sequential search(search one of the elements),using insertion sort(sort the element) and using selection sort(sort the element).
Why is destructor used?
What is byval and byref? What are differences between them?
What is new keyword in oops?
What is difference between pop and oop?
What is encapsulation with example?
What makes a language oop?