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.
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.
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)
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.
Abhishek Singh said:
1 decade ago
If object of derived class is created, then constructor of derived class is called automatically, and if base class constructor has same name, then it is called also.
Same scenario will be happened if Destructor of base class is not virtual.
so it should always be virtual.
Same scenario will be happened if Destructor of base class is not virtual.
so it should always be virtual.
Abhishek Singh said:
1 decade ago
If object of derived class is created, then constructor of derived class is called automatically, and if base class constructor has same name, then it is called also.
Same scenario will be happened if Destructor of base class is not virtual.
Same scenario will be happened if Destructor of base class is not 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.
Ashish said:
1 decade ago
Because the initialization of base class objects must not be destroyed by deleting object of derived class. That is base class destructor must not be called upon calling derived class destructor.
Naseem asraf said:
1 decade ago
Because the initialization of base class objects must not be destroyed by deleting object of derived class. That is base class destructor must not be called upon calling derived class destructor.
Nagnath said:
1 decade ago
Because the initialization of base class objects must not be destroyed by deleting object of derived class. That is base class destructor must not be called upon calling derived class destructor.
Chandu reddy said:
6 years ago
What is the difference between pure virtual and absult virtual class?
(2)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers