N3797的3.4.3.1/1开头说:
If the nested-name-specifier of a qualified-id nominates a class, the name specified after the nested-name-specifier is looked up in the scope of the class (10.2), except for the cases listed below.
其中一条规则是:
the lookup for a name specified in a using-declaration (7.3.3) also finds class or enumeration names hidden within the same scope (3.3.10).
你能举个例子来证明这个规则吗?
最佳答案
我相信这就是标准提供的内容:
struct A {
struct s {} s;
enum e { e };
};
struct B: A {
using A::s;
using A::e;
};
struct B::s s2;
enum B::e e2;
B
范围内的 using-declaration 将类和枚举名称 A::s
和 纳入范围A::e
,即使它们分别被成员和枚举数隐藏。
请注意,using-declaration 还将成员和枚举数纳入范围,因此类和枚举仍隐藏在 B
的范围内;这意味着要在 B
或其他地方使用它们,我们需要使用 struct
和 enum
标签。
关于c++ - 使用声明的类或枚举,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24124493/