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

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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

write a program to find 2^n+1 ?

1540


Where You Can Use Interface in your Project

1419


Question: Write a program that prints a paycheck. Ask the program user for the name of the employee, the hourly rate, and the number of hours worked. If the number of hours exceeds 40, the employee is paid “time and a half”, that is, 150 percent of the hourly rate on the hours exceeding 40. Be sure to use stepwi se refine ment and break your solution into several functions. Use the int_name function to print the dollar amount of the check.

687


Why is polymorphism important in oop?

624


Which method cannot be overridden?

572






What is object and class in oops?

573


Why do pointers exist?

651


what is different between oops and c++

1992


i=20;k=0; for(j=1;k-i;k+=j<10?4:3) { cout<

1409


How do you answer polymorphism?

575


What type of loop is a for loop?

677


Can private class be inherited?

611


what is graphics

2000


What is abstract class in oop?

526


What is abstract class in oops?

592