班级声明中的全球资格 班长
我们发现了类似于以下内容的内容(不要问...):
namespace N {
struct A { struct B; };
}
struct A { struct B; };
using namespace N;
struct ::A::B {}; // <- point of interest
有趣的是,这可以在 VS2005、icc 11.1 和 Comeau(在线)上编译良好,但在 GCC 上会失败:
类名的全局限定在“{”标记之前无效
从C++03,附件A,在我看来GCC是正确的:
class-head
可以由nested-name组成-specifier
和identifier
nested-name-specifier
不能以全局限定符 (::
) 开头- ,显然,两者都不能
identifier
...或者我忽略了什么?
We found something similar to the following (don't ask ...):
namespace N {
struct A { struct B; };
}
struct A { struct B; };
using namespace N;
struct ::A::B {}; // <- point of interest
Interestingly, this compiles fine with VS2005, icc 11.1 and Comeau (online), but fails with GCC:
global qualification of class name is invalid before '{' token
From C++03, Annex A, it seems to me like GCC is right:
- the
class-head
can consist ofnested-name-specifier
andidentifier
nested-name-specifier
can't begin with a global qualification (::
)- obviously, neither can
identifier
... or am i overlooking something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你说得对:在这种情况下,GCC 严格执行了标准,而其他人则执行得不太严格(看看 问题#355)。
您可以执行以下操作来解决语法的限制
或者您使用显式命名的
typedef
或者,当然,您可以交换
using namespace
和嵌套的顺序类定义。请注意,附录 A 仅供参考。规范性文本位于条款5.1/7
和9
中。I think you are getting it right: GCC implements the standard to the letter in this case, while the others implement it less strict (have a look at issue #355).
You could do the following to work-around the limitation of the syntax
Or you use an explicit named
typedef
Or, of course, you exchange the order of
using namespace
and the nested class definition. Notice that Annex A is informative only. The normative text is at clauses5.1/7
and9
.