Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How are namespaces declared in cppreference.com?


Asked by Hallie Daniels on Dec 08, 2021 FAQ



Namespaces. Symbols declared inside a namespace block are placed in a named scope that prevents them from being mistaken for identically-named symbols in other scopes. Multiple namespace blocks with the same name are allowed. All declarations within those blocks are declared in the named scope.
Also Know,
From cppreference.com: Namespaces provide a method for preventing name conflicts in large projects. Symbols declared inside a namespace block are placed in a named scope that prevents them from being mistaken for identically-named symbols in other scopes. Multiple namespace blocks with the same name are allowed.
In addition, A name first declared in a friend declaration within a class or class template X becomes a member of the innermost enclosing namespace of X, but is not visible for lookup (except argument-dependent lookup that considers X) unless a matching declaration at the namespace scope is provided - see namespaces for details.
Likewise,
Name lookup rules make it impractical to declare operators in global or user-defined namespace that operate on types from the std namespace, e.g. a custom operator>> or operator+ for std::vector or for std::pair (unless the element types of the vector/pair are user-defined types, which would add their namespace to ADL).
Consequently,
Cannot appear on the extension-namespace-definition if the original-namespace-definition did not use inline Namespace definitions are only allowed at namespace scope, including the global scope.