Search code examples
c++visual-c++structmsvc12

qualified names in C++ class declaration


According to this page, the class name can be "optionally qualified". Thus, I expect the following code to compile:

struct ::globalSt {};

In MSVC 2013u4, I get an error:

Error 1 error C2039: 'globalSt' : is not a member of '`global namespace''

Am I misinterpreting the reference or is that a MSVC bug?


Solution

  • If you define a class with a qualified name, the name must have been previously declared. [class]/11

    If a class-head-name contains a nested-name-specifier, the class-specifier shall refer to a class that was previously declared directly in the class or namespace to which the nested-name-specifier refers, or in an element of the inline namespace set (7.3.1) of that namespace (i.e., not merely inherited or introduced by a using-declaration), and the class-specifier shall appear in a namespace enclosing the previous declaration. In such cases, the nested-name-specifier of the class-head-name of the definition shall not begin with a decltype-specifier.