6

What is the difference between:

namespace A
{
    inline namespace B
    {
        ...
    }

    ...
}

...

and

namespace A
{
    namespace B
    {
        ...
    }

    using namespace B;

    ...
}

...

That is, what is the difference between an inline namespace, and a non-inline namespace with a using directive placed in its enclosing namespace?

Andrew Tomazos
  • 66,139
  • 40
  • 186
  • 319
  • 1
    IMO this question should be reopened because is different from the linked "duplicate" in that it specifically asks for the specific difference between the feature and an apparently equivalent construction. – Catskul Feb 04 '20 at 16:27
  • 1
    @Catskul: As you wish – Andrew Tomazos Feb 05 '20 at 12:31

1 Answers1

2

Paraphrased from C++11 7.3.1p8:

  • The inline namespace and its enclosing namespace are both added to the set of associated namespaces used in argument-dependent lookup whenever one of them is.

  • Each member of the inline namespace can subsequently be explicitly instantiated or explicitly specialized as though it were a member of the enclosing namespace.

  • Looking up a name in the enclosing namespace via explicit qualification will include members of the inline namespace brought in by the using-directive even if there are declarations of that name in the enclosing namespace.

Andrew Tomazos
  • 66,139
  • 40
  • 186
  • 319