成员函数声明中是否允许限定名称?
该代码被MSVC9.0接受。我的问题是根据标准(旧的和/或新的)它是否合法。也非常欢迎报价。
class X
{
void X::f();
};
This code is accepted by MSVC9.0. My question is whether it is legal according to the standard (the old and/or the new one). A quote would be very much welcome, too.
class X
{
void X::f();
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,这是无效的。这里,
X::f
是一个限定名称;您正尝试将其用作declarator-id。 C++03 8.3[dcl.meaning]/1 列出了可以限定 declarator-id 的情况:因为
X::f
不属于这四个类别中的任何一个,所以它是不正确的。要求类定义之外的成员函数定义被限定的规则可以在 C++03 9.3[class.mfct]/5 中找到:
No, this is not valid. Here,
X::f
is a qualified name; you are attempting to use it as a declarator-id. C++03 8.3[dcl.meaning]/1 lists the circumstances under which a declarator-id may be qualified:Because
X::f
falls into none of these four categories, it is incorrect.The rule that requires the definition of a member function outside of the class definition to be qualified can be found at C++03 9.3[class.mfct]/5:
据我了解,根据 C++03 规范,它无效。
参考 - C++03 标准:
第 $8.3 节:
每个声明符仅包含一个声明符 ID;它命名所声明的标识符。除了一些特殊函数的声明(12.3、12.4、13.5)以及模板特化或部分特化(14.7)的声明外,声明符 id 的 id 表达式应是一个简单标识符。 declarator-id 不得被限定,除非在其类之外定义了成员函数 (9.3) 或静态数据成员 (9.4) 或嵌套类 (9.7),其名称空间之外的名称空间的函数、变量或类成员,或先前在其名称空间之外声明的显式特化的定义,或作为另一个类或名称空间的成员的友元函数的声明 (11.4)。< /em>
我希望我能得出上述内容的适当含义。我承认阅读&理解标准中的引文让我有点头晕。如果我解释错误请告诉我。
As I understand it is Not valid as per the C++03 Specification.
Reference - C++03 standard:
Section $8.3:
Each declarator contains exactly one declarator-id; it names the identifier that is declared. The id-expression of a declarator-id shall be a simple identifier except for the declaration of some special functions (12.3, 12.4, 13.5) and for the declaration of template specializations or partial specializations (14.7). A declarator-id shall not be qualified except for the definition of a member function (9.3) or static data member (9.4) or nested class (9.7) outside of its class, the definition or explicit instantiation of a function, variable or class member of a namespace outside of its namespace, or the definition of a previously declared explicit specialization outside of its namespace, or the declaration of a friend function that is a member of another class or namespace (11.4).
I hope I am deriving the appropriate meaning of the above. I will admit reading & understanding the quotes from the Standard makes me a little dizzy. Let me know if I interpret it wrongly.