title: Forward declaring a function in a namespace inside another function in that namespace
body: <p>I have two source files, <code>a.cpp</code> and <code>b.cpp</code>. In <code>a.cpp</code>, I have a function, <code>foo</code>:</p>
  
  <pre><code>namespace ns { void foo() { std::cout &lt;&lt; "foo!"; } }
  </code></pre>
  
  <p>In <code>b.cpp</code>, I have another function in namespace <code>ns</code> in which I'd like to prototype and call <code>foo</code>:</p>
  
  <pre><code>namespace ns
  {
  
  void bar()
  {
      void foo();
      foo();       
  }
  
  }
  </code></pre>
  
  <p>While the above is syntactically valid, it leads the compiler to think that <code>foo</code> is in the global namespace (or at least that's what I've deduced from the linker errors I get when I do this). My first two ideas to fix that were <code>void ns::foo();</code> and <code>namespace ns { void foo(); }</code>, but neither is valid. Is it possible to correctly prototype this function inside <code>bar</code>? </p>
  
  <p>Note that I know I could simply move this to the file scope or a header file, there have been many questions asked about this, but I want to specifically prototype it inside another function. My compiler is MSVC 14.0 with the latest update.</p>
  
  <p><strong>EDIT:</strong> Based on some tests I've done and our discussion in the comments, I believe this is an MSVC bug. Compare:</p>
  
  <pre><code>namespace ns
  {
  
  void bar()
  {
      void foo();   // link error, MSVC assumes global namespace
      foo();
  }
  
  void foo() { }
  
  } // namespace ns
  </code></pre>
  
  <p>This fails, as stated previously. However, moving the prototype out of the function makes MSVC correctly place the prototyped function in the enclosing namespace:</p>
  
  <pre><code>namespace ns
  {
  
  void foo();   // all fine
  void bar()
  {
      foo();
  }
  
  void foo() { }
  
  } // namespace ns
  </code></pre>