C++ Programming - Objects and Classes - Discussion
Discussion Forum : Objects and Classes - General Questions (Q.No. 3)
3.
Which of the following statement is correct regarding destructor of base class?
Discussion:
15 comments Page 1 of 2.
Chandu reddy said:
6 years ago
What is the difference between pure virtual and absult virtual class?
(2)
Sumit sharma said:
9 years ago
Significance of virtual function is to provide late binding by restricting the early binding. So destructor should be always virtual so respective descended class's destruction execute instead of parent class destructior, when accesed through pointer as a refrence of the oblect.
Gaurav said:
9 years ago
There is no need to use destructor as virtual because the principle of destructor is to delete the constructor and free the memory allocated by constructor and virtual function should transfer the function call from base class to derive i.e. if want to delete the constructor of both the classes but the can't happen it should be delete only derived class object.
Divya Agrawal said:
9 years ago
But how destructor uses virtual? It is not getting.
Shaan said:
1 decade ago
Because if we assign derived class in to base class pointer then if we call delete then only base class destructor will call, base class destructor will not call.
So object will not fully destroy. And now if the destructor of base class is virtual then derived class destructor will call and object will fully destroy.
So object will not fully destroy. And now if the destructor of base class is virtual then derived class destructor will call and object will fully destroy.
(1)
Keerthana said:
1 decade ago
What happens if destructor is not virtual?
GURIYA said:
1 decade ago
Because constructor is not contained Virtual method table in memory.
Shalin said:
1 decade ago
Why constructor can not be created virtual?
Ajay said:
1 decade ago
why we use concept of virtual?
Neha said:
1 decade ago
Because, the initialization of base class object must not be destroyed by deleting object of derived class. That is base class.
Destructor must not be called upon calling derived class destructor.
Destructor must not be called upon calling derived class destructor.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers