addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobegmailgooglegroupshelp-with-circleimageimagesinstagramlinklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruserwarningyahoo

Why is taking the address of a destructor forbidden?

From: Fabio A.
Sent on: Wednesday, October 26, 2011 6:58 PM
Hello everybody. 

C++ standard at[masked] states that

[...] The address of a destructor shall not be taken. [...]

However, one can without any complaints by the compiler take the address of a wrapper around a class destructor, like this:

struct Test {
   
~Test(){};

   
void destructor(){
       
this->~Test();
   
}
};

void (Test::*d)() = &Test::destructor;

So what's the rationale behind forbidding to take the address of a destructor directly?

I posted this question on Stack Overflow as well, but I thought I'd ask here too. The most voted up answer there seems convincing at a first sight, but during the discussion I came up with some objections I've so far had no convincing answer to.

Thanks in advance for your replies!
Fabio



People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy