析构函数不应使用指针来声明吗?在 C++
在 C++0x -n3290 草案中:他们在 :Destructors: 12.4/2nd 点最后一行中添加了
**A destructor shall not be declared with a ref-qualifier.**
在 c++03 草案中....他们没有在析构函数中提到这一点?
我的问题是是否
*~S() ; //this declaration is allowed or not according to the Standard's
//**~S(); ***~S() ; etc...........
允许这种类型的声明? 他在草案中没有描述这个……声明?
在 GCC 4.6.0,Sun/Oracle C++12.0 中,--->允许此声明 int Comeau C/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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这看起来不像是任何类型的合法函数声明,更不用说析构函数了。我不确定标准的这一部分在谈论什么,但我有一个猜测。
我怀疑有一个限定符表示您的函数正在右值引用上调用。像这样的事情:
我认为标准中的语言是说析构函数上不允许使用此限定符,就像尾随 const 也是非法的一样。
而且,经过进一步的调查,我对自己的猜测的正确性的确信度大大提高了。理由如下:
*这个
。其中明确指出,函数现在可以在“cv-qualifer”之后有一个“ref-qualifier”。这意味着函数声明现在可以后跟
const &
或const volatile &&
而不仅仅是const
。使用的术语(引用限定符)与您引用的标准中使用的术语相同。析构函数不能拥有析构函数是有道理的。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:
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:
*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 &
orconst volatile &&
instead of justconst
. 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.您误解了新标准中ref-qualifier的含义。就像您可以为 C++03 中的任何成员函数提供
const
限定符一样,您也可以为 C+ 中的成员函数添加 ref-qualifier +0x。该修饰符将影响函数隐式this
参数的类型:就像析构函数不能是
static
或const
一样,或 C++03 中的const volatile
,它不能采用引用限定符(&
或&&) 在 C++0x 中。当然,以前的标准中不存在这一点。
You have misunderstood what ref-qualifier means in the new standard. In the same way that you can provide a
const
qualifier to any member function in C++03, you can also add a ref-qualifier to a member function in C++0x. That modifier will affect the type of the implicitthis
argument to the function:In the same way that a destructor cannot be
static
, orconst
, orconst volatile
in C++03, it cannot take a ref-qualifier (&
or&&
) in C++0x. Of course this bit was not present in the former standard.您正在寻找的规则在同一段中说明,12.4p2
“不能为它指定返回类型”这句话也禁止了“*”,这不是立即清楚的,但可以通过与 12.3.2p1 比较来看出(与 此问题报告):
该规则使得实现禁止
* operator int() { }
。您也可以与 12.4p1 争论,尽管它的措辞非常笼统,并且是析构函数部分中的第一个语句,我认为上面的其他语句应该是主要参数可以看到/读到,该描述中没有提及诸如
*
之类的声明符,这表明了作者的意图。The rule you are looking for is stated in the same paragraph, 12.4p2
The phrase "no return type can be specified for it" also forbids "*", which is not immediately clear but can be seen by comparison with 12.3.2p1 (compare with this issue report):
That rule is what makes implementations forbid
* operator int() { }
. You can also argue with 12.4p1, although as that's phrased very general and is the first statement in the destructors section, I think the other statement above should be the primary argumentAs can be seen/read there is no mention of declarators such as
*
in that description, which shows the intent of the authors.