Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A destructor Shall OR shall not be declared with a pointer ? in C++

In C++0x -n3290 Draft : they added in section :Destructors : 12.4/2nd point last line

          **A destructor shall not be declared with a ref-qualifier.**

In c++03 Draft .... they didn't mention this point in destructors ?

my question is whether

   *~S() ;   //this declaration is allowed or not according to the Standard's
   //**~S(); ***~S() ; etc...........

this type of declaration is allowed ? No where in the Draft he described about this ...Declaration?

In GCC 4.6.0,Sun/Oracle C++12.0 , --->this declaration is allowed int Comeau C/C++ -->not allowed

like image 338
user751747 Avatar asked Sep 07 '11 06:09

user751747


1 Answers

That doesn't look like it would ever be a legal function declaration of any kind, much less for a destructor. I'm not positive what that part of the standard is talking about, but I have a guess.

I suspect there is a qualifier saying that your function is being called on an rvalue reference. Something like this:

class A {
 public:
   void IAmAnRValue() &&;
};

I think the language in the standard is saying that this qualifier is not allowed on a destructor, much like having a trailing const would also be illegal.

And, on further investigation, my certainty of the correctness of my surmise goes up considerably. Here is the justification:

  • Extending Move Semantics to *this.

There it clearly states that functions may now have a 'ref-qualifier' after the 'cv-qualifer'. This means that a function declaration may now be followed by const & or const volatile && instead of just const. And the term used (ref-qualifier) is the same as the term used in the little bit of the standard you're quoting. And it makes sense for destructors to not be able to have one.

like image 78
Omnifarious Avatar answered Nov 15 '22 04:11

Omnifarious