title: What is the difference between "using namespace Bar" and "using Bar::Foo"?
body: <p>I have the code:</p>
  <pre><code>#include &lt;iostream&gt;
  
  class Foo {
  
  };
  
  namespace Bar {
      struct Foo {
  
      };
  }
  
  namespace Baz
  {
      void baz(const Foo &amp;)
      {
          std::cout &lt;&lt; &quot;Hello&quot;;
      }
  }
  
  int main()
  {
      Baz::baz(Bar::Foo());
  }
  
  </code></pre>
  <p>Compiler can't figure out which <code>Foo</code> want to use and produces the error:</p>
  <pre><code>main.cpp: In function 'int main()':
  main.cpp:23:19: error: invalid initialization of reference of type 'const Foo&amp;' from expression of type 'Bar::Foo'
     23 |     Baz::baz(Bar::Foo());
        |                   ^~~~~
  main.cpp:15:14: note: in passing argument 1 of 'void Baz::baz(const Foo&amp;)'
     15 |     void baz(const Foo &amp;)
        |   
  </code></pre>
  <p><a href="http://coliru.stacked-crooked.com/a/925d64bc4f34571f" rel="nofollow noreferrer">Online compiler</a></p>
  <hr />
  <p>Of course the simplest solution is to use either <code>::Foo</code> or <code>::Baz::Foo</code>, but I want to fix all possible ambiguities with O(1) lines of code.</p>
  <p>My first idea was <code>using namespace Bar</code> inside <code>Baz</code> namespace:</p>
  <pre><code>namespace Baz
  {
  using namespace Baz;
  //...
  </code></pre>
  <blockquote>
  <p>using-declaration: makes the symbol name from the namespace ns_name accessible for unqualified lookup as if declared in the same class scope, block scope, or namespace as where this using-declaration appears.</p>
  </blockquote>
  <p>I expected that all <code>Bar</code> names become part of <code>Baz</code> namespace, and unqualified lookup prefers <code>Baz::Foo</code>. But for some reason it doesn't work</p>
  <p><a href="http://coliru.stacked-crooked.com/a/c0302f133132abf3" rel="nofollow noreferrer">Online compiler</a></p>
  <hr />
  <p>But <code>using Bar::Foo;</code>, in turn, does the trick. And that confuses me even more</p>
  <pre><code>namespace Baz
  {
      using Bar::Foo;
  </code></pre>
  <p><a href="http://coliru.stacked-crooked.com/a/59fc44a7d9f33065" rel="nofollow noreferrer">Online compiler</a></p>
  <hr />
  <p>So, my question is: What is the difference between <code>using namespace Bar</code> and <code>using Bar::Foo</code> in this case?</p>