Search code examples
c++classenumerationusinglanguage-lawyer

Class or enumeration using declaration


The beginning of 3.4.3.1/1 of N3797 said:

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.

and one of this rules is:

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).

Can you get an example to demonstrate that rule?


Solution

  • I believe this is what the standard provides:

    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;
    

    The using-declarations in the scope of B bring into scope the class and enumeration names A::s and A::e, even though they are hidden by a member and enumerator respectively.

    Note that the using-declarations also bring into scope the member and enumerator, so the class and enumeration are still hidden within the scope of B; this means that to use them within B or elsewhere we need to use the struct and enum tags.