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

Explain the concepts involved in Object Oriented programming.

638


What is abstract class in oop?

534


How many human genes are polymorphic?

575


How do you define a class in oop?

628


What is a function in oop?

633






Why do we use polymorphism in oops?

581


Do you know about multiple inheritance?

641


What are oops methods?

568


What is the full form of oops?

612


Can main method override?

585


What are constructors in oop?

594


What is difference between data abstraction and encapsulation?

617


What is the oops and benefits of oops programming?

555


What is the real life example of polymorphism?

609


What is inheritance write a program to show use of inheritance?

613