The article Are destructors overloadable? talks about overloading the destructor.
This raised a question: Can a destructor have parameters?
I've never used or seen a destructor with parameters. I could not come up with an example of a reason to use parameters to the destructor.
A special declarator syntax using an optional function-specifier (7.1. 2) followed by ˜ followed by the destructor's class name followed by an empty parameter list is used to declare the destructor in a class definition. So no, destructors do not take parameters.
Destructor rules 3) Unlike constructors that can have parameters, destructors do not allow any parameter.
Properties of Destructor:The destructor does not have arguments. It has no return type not even void. An object of a class with a Destructor cannot become a member of the union. A destructor should be declared in the public section of the class.
There are specific rules that make an overloaded delete function a destructor function: the function must have just one input argument, which is an object of the class, and it must not have any output arguments.
Section §12.4 of C++0x draft n3290 has this to say about destructors:
Destructors
A special declarator syntax using an optional function-specifier (7.1.2) followed by ˜ followed by the destructor’s class name followed by an empty parameter list is used to declare the destructor in a class definition.
(emphasis added)
So no, destructors do not take parameters. (The 2003 standard has the exact wording of the above paragraph.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With