Search code examples
c++namespacesusing

"using namespace" in header in namspace


I know that a question very similar has been asked before, "using namespace" in c++ headers, but mine is when its inside of a namespace.

namespace foo {
    using namespace std; // what does this do?

    class Bar { ... }
}

Does this do exactly the same thing as the other question says and just include that using statement everywhere? Does it only do it in that namespace? Does it only do it in that header?


Solution

  • There are two differences:

    1. Yes, the using will only apply to code inside the foo namespace. But that means all foo code that sees this header, so you probably still don't want to do it.
    2. If the namespace foo::std exists, the nested using statement will favor it over ::std.