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

Why do we need polymorphism in c#?

683


What are the types of abstraction?

551


what is the 3 types of system development life cycle

2429


What is interface in oop?

656


What is difference between data abstraction and encapsulation?

613






What does <> mean pseudocode?

618


What are the benefits of oop?

601


What is encapsulation in simple terms?

535


Can bst contain duplicates?

664


What is encapsulation c#?

598


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.

1535


What is abstract class in oops?

594


What is abstraction encapsulation?

653


Why is static class not inherited?

591


What is the main purpose of inheritance law?

666