C ++ nested namespace definitions that start with ::

In draft §7.3.1¶1 (n4527), the namespace definition grammar contains:

wired-namespace specifier:

identifier

     

encing-namespace-specifier :: identifier

This prevents namespace definitions by identifiers starting with '::'

namespace d{ namespace e {} }
namespace ::d::e
{
void foo(){}
}

Is there a reason for this limitation?


Update: The bottom part (s) and some of the answers made it clear to me that I wrote "standard" when I meant "project" in the very first sentence. In my defense, I wrote the document number in parentheses. So let me emphasize that this is a question about the function of defining nested C ++ 1z namespaces.

+4
2

, ::, , . :

void foo()
{
  std::cout << "1" << std::endl;
}

namespace d
{
  void foo()
  {
    std::cout << "2" << std::endl;
  }

  void example()
  {
    foo();
    ::foo();
  }
}

:

2
1

d::foo(), foo() . , :: , d , , .

0

A:: :

void f();
namespace A {
  void f();
  namespace B {
    void f();
    void g() {
      A::f();      // #1
      ::f();
    }
  }
}
namespace A::N {}  // #2
namespace /*::*/N {}
  • , B::f, . , ::f;.
  • ( ) . , , , ::N .
0

Source: https://habr.com/ru/post/1615267/


All Articles