Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Destructor parameters

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.

like image 837
Thomas Matthews Avatar asked Jun 05 '11 19:06

Thomas Matthews


People also ask

Can destructor have parameters?

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.

How many parameters can a destructor take?

Destructor rules 3) Unlike constructors that can have parameters, destructors do not allow any parameter.

Can destructor have arguments C++?

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.

How many arguments does a destructor take in C++?

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.


1 Answers

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.)

like image 187
Mat Avatar answered Oct 11 '22 13:10

Mat