use*_*747 8 c++ destructor declaration c++11
在C++ 0x -n3290草案中:他们在章节中添加了:Destructors:12.4/2nd point last line
**A destructor shall not be declared with a ref-qualifier.**
Run Code Online (Sandbox Code Playgroud)
在c ++ 03 Draft ....他们没有在析构函数中提到这一点?
我的问题是,是否
*~S() ; //this declaration is allowed or not according to the Standard's
//**~S(); ***~S() ; etc...........
Run Code Online (Sandbox Code Playgroud)
允许这种类型的声明?他没有在草案中描述过这个......宣言?
在GCC 4.6.0中,Sun/Oracle C++ 12.0,--->这个声明允许使用Comeau C/C++ - >不允许
Omn*_*ous 10
这似乎不是任何类型的合法函数声明,更不用说析构函数了.我不是肯定标准的那部分是在谈论什么,但我有一个猜测.
我怀疑有一个限定符说你的函数是在右值引用上调用的.像这样的东西:
class A {
public:
void IAmAnRValue() &&;
};
Run Code Online (Sandbox Code Playgroud)
我认为标准中的语言是说析构函数不允许使用此限定符,就像使用尾随const也是非法的一样.
并且,在进一步调查中,我对我的猜测正确性的确定性大大提高.这是理由:
在那里它清楚地表明,在'cv-qualifer'之后,函数现在可能具有'ref-qualifier'.这意味着函数声明现在可以跟随const &或const volatile &&代替const.使用的术语(ref-qualifier)与您引用的标准中使用的术语相同.析构函数无法拥有它是有道理的.
您误解了新标准中的ref-qualifier含义.与const在C++ 03中为任何成员函数提供限定符的方式相同,您还可以在C++ 0x中向成员函数添加ref-qualifier.该修饰符将影响this函数的隐式参数的类型:
struct test {
void f() const &&; // implicit "this" in "f" is of type "test const &&"
};
Run Code Online (Sandbox Code Playgroud)
在同样的方式,析构函数不能static,或const,或const volatile在C++ 03,它不能采取REF-限定符(&或&&C++ 0x中).当然,这个位在前一个标准中并不存在.
| 归档时间: |
|
| 查看次数: |
237 次 |
| 最近记录: |