共用方式為


Defining namespace Members

Members of a namespace may be defined within that namespace. For example:

namespace X { void f() { } }

Members of a named namespace can be defined outside the namespace in which they are declared by explicit qualification of the name being defined. However, the entity being defined must already be declared in the namespace. In addition, the definition must appear after the point of declaration in a namespace that encloses the declaration's namespace. For example:

// defining_namespace_members.cpp
// C2039 expected
namespace Q {
    namespace V {
        void f();
    }

    void V::f() { }        // ok
    void V::g() { }        // C2039, g() is not yet a member of V

    namespace V {
        void g();
    }
}

See Also

Reference

Namespaces (C++)