title: Why using directive behaves differently in global scope and in local scope?
body: <p>When I write following code it gets compiled and executed properly:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  namespace first
  {
    int x = 5;
    int y = 10;
  }
  
  namespace second
  {
    double x = 3.1416;
    double y = 2.7183;
  }
  
  int main () {
    using namespace first; //using derective
    using second::y;
    cout &lt;&lt; x &lt;&lt; endl;
    cout &lt;&lt; y &lt;&lt; endl;
    return 0;
  }
  </code></pre>
  
  <p>But if I write using directives outside main function as follows,</p>
  
  <pre><code>using namespace first; //using derective
  using second::y;
  int main () {
    cout &lt;&lt; x &lt;&lt; endl;
    cout &lt;&lt; y &lt;&lt; endl;
    return 0;
  }
  </code></pre>
  
  <p>It gives this compilation error:</p>
  
  <pre><code>g++     namespace03.cpp   -o namespace03
  namespace03.cpp: In function ‘int main()’:
  namespace03.cpp:20:11: error: reference to ‘y’ is ambiguous
  namespace03.cpp:13:10: error: candidates are: double second::y
  namespace03.cpp:7:7: error:                 int first::y
  make: *** [namespace03] Error 1
  </code></pre>
  
  <p>Can anybody explain why using directive behaves differently when it is used inside <code>main</code> and outside <code>main</code>?</p>