Andrew Tomazos
Andrew Tomazos

Reputation: 68708

Difference in C++11 between inline namespace and using directive?

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?

Upvotes: 6

Views: 949

Answers (1)

Andrew Tomazos
Andrew Tomazos

Reputation: 68708

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.

Upvotes: 2

Related Questions