Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

c++11

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?

like image 868
Andrew Tomazos Avatar asked Nov 13 '22 01:11

Andrew Tomazos


1 Answers

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.

like image 128
Andrew Tomazos Avatar answered Nov 15 '22 05:11

Andrew Tomazos