C++ Programming - Constructors and Destructors - Discussion
Discussion Forum : Constructors and Destructors - General Questions (Q.No. 28)
                   
                                       
                                28.
A destructor takes __________ arguments.
 
                                    Discussion:
1 comments Page 1 of 1.
                
                        Shashi said: 
                         
                        7 years ago
                
                Destructors are called automatically most of the time when the object gets out of scope, the containing object, or a child object is getting destroyed. There is no natural place to pass arguments in these cases.
Destructors can be invoked directly through the delete operator or through type::~type (). These are typically called in low-level code, which most programmers don't have to deal with. In theory, it was possible to pass arguments with these invocations of destructors.
Even though C++ could have allowed delete (param) object (currently it means something different) and object. ~type (param) , this would have needlessly complicated the language. I can see nothing that a destructor can do with parameters, which can't be achieved by an earlier function call. Having the destructor do only one thing - single kind of clean up - makes things simpler.
                Destructors can be invoked directly through the delete operator or through type::~type (). These are typically called in low-level code, which most programmers don't have to deal with. In theory, it was possible to pass arguments with these invocations of destructors.
Even though C++ could have allowed delete (param) object (currently it means something different) and object. ~type (param) , this would have needlessly complicated the language. I can see nothing that a destructor can do with parameters, which can't be achieved by an earlier function call. Having the destructor do only one thing - single kind of clean up - makes things simpler.
Post your comments here:
 
            
        Quick links
                            Quantitative Aptitude
                                    
                                    Verbal (English)
                                    
                                    Reasoning
                                    
                                Programming
                                    
                                    Interview
                                    
                                     Placement Papers