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
write a program to find 2^n+1 ?
Where You Can Use Interface in your Project
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.
Why is polymorphism important in oop?
Which method cannot be overridden?
What is object and class in oops?
Why do pointers exist?
what is different between oops and c++
i=20;k=0;
for(j=1;k-i;k+=j<10?4:3)
{
cout< How do you answer polymorphism? What type of loop is a for loop? Can private class be inherited? what is graphics What is abstract class in oop? What is abstract class in oops?