Local function declaration inside namespace

后端 未结 2 1444
旧巷少年郎
旧巷少年郎 2021-01-05 01:35

In such a situation

namespace n {
    void f() {
        void another_function();
    }
}

Should the function another_function

2条回答
  •  没有蜡笔的小新
    2021-01-05 01:46

    According to N3485 7.3.1 [namespace.def]/6, the correct answer is n::another_function.

    The enclosing namespaces of a declaration are those namespaces in which the declaration lexically appears, except for a redeclaration of a namespace member outside its original namespace (e.g., a definition as specified in 7.3.1.2). Such a redeclaration has the same enclosing namespaces as the original declaration. [ Example:

    namespace Q {
        namespace V {
            void f(); // enclosing namespaces are the global namespace, Q, and Q::V
            class C { void m(); };
        }
        void V::f() { // enclosing namespaces are the global namespace, Q, and Q::V
            extern void h(); // ... so this declares Q::V::h
        }
        void V::C::m() { // enclosing namespaces are the global namespace, Q, and Q::V
        }
    }
    

    —end example ]

提交回复
热议问题