Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


In c++ there is only virtual destructors, no constructors. Why?

Answers were Sorted based on User's Feedback



In c++ there is only virtual destructors, no constructors. Why?..

Answer / uma sankar pradhan

constructors are invoked at the time of object creation.
The v-table for virtual function mechanism is not
intialised properly during the constructor invocation.
So constructors cannot be virtual

But,destructors can be virtual.Because the V-table is
properly initialised at the time of object creation.
So the v-table is available for the destructors.
Destructors can be made pure virtual also.But unlike other
member functions,it must be redfined outside the class.

Is This Answer Correct ?    57 Yes 22 No

In c++ there is only virtual destructors, no constructors. Why?..

Answer / bala preethi

Since OOPS basics says always base class object to be
created and than its derivatives. So just consider the case
where we try to create object of derived class with virtual
contructor since pointer points to derived type object it
fetches derived constructor directly, without its base
class object constructed( instantiated )...
So Constructor cannot be made virtual bt when comes to case
of Destructor object destuction process must be reverse...
So we must make destructor as virtual.
This applies only when we going for Dynamic Memory
Allocation...

If, on the other hand, you were to have a pointer to object
A and assign it a dynamic object B, when you destroy it,
only object A's destructor is called and object B part of
the object is never destroyed. Virtual destructors are used
to solve this problem and destroy the objects in the right
order.

Is This Answer Correct ?    47 Yes 14 No

In c++ there is only virtual destructors, no constructors. Why?..

Answer / 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

In c++ there is only virtual destructors, no constructors. Why?..

Answer / jos collin

The VTable is created at compile-time itself. But properly
initialized at runtime, including vptr.

Virtual Mechanism is possible only with completely
constructed objects. The constructor is called when the
object is not created completely, it is not allowed.

Is This Answer Correct ?    0 Yes 6 No

Post New Answer

More OOPS Interview Questions

What is object in oops?

0 Answers  


What is the types of inheritance?

0 Answers  


write a program to enter a string like"sunil is a good boy and seeking for a job" not more than 10 characters including space in one line,rest characters should b in other line.if the next line starts from in between the previous word,then print whole word to next line.

0 Answers   Wipro,


What is class and object with example?

0 Answers  


What is DeadlyDiamondDeathProblem ?

1 Answers  


What do you mean by public, private, protected and friendly?

3 Answers   CA,


Prepare me a program for the animation of train

0 Answers  


program in c++ that can either 2 integers or 2 floating point numbers and output the smallest number

1 Answers   Anna University,


What is meant by oops concept?

0 Answers  


What is a class oop?

0 Answers  


What is the difference between class and structure?

7 Answers  


What do you mean by inheritance?

0 Answers   IBS,


Categories