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


Please Help Members By Posting Answers For Below Questions

What is an advantage of polymorphism?

585


Why interface is used?

547


what is the drawback of classical methods in oops?

2908


Can a destructor be called directly?

591


Will I be able to get a picture in D drive to the c++ program? If so, help me out?

1648






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.

1447


What is encapsulation and abstraction? How are they implemented in C++?

628


write a programe to calculate the simple intrest and compund intrest using by function overlading

1658


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).

1662


Why is destructor used?

574


What is byval and byref? What are differences between them?

1680


What is new keyword in oops?

585


What is difference between pop and oop?

597


What is encapsulation with example?

570


What makes a language oop?

589