namespace query
<p>The below code give the compilation error</p>

<pre><code>namespace X{
  int i;
}

void f(){

  int i;
  using X::i;  //compile error 'i’ is already declared in this scope

}
</code></pre>

<p>But if i replace this line with using namespace X, it compiles fine.
Can someone help understand differences.</p>

<p>Also in the modified code below, I was expecting the output for X::I to be 100 in all places, but it is not.</p>

<p>May be I have misunderstood the namespace concept ?</p>

<pre><code>namespace X{
  int i;
}

void f(){
  int i=1;
  cout &lt;&lt; "local I " &lt;&lt; i &lt;&lt; endl;  // prints 1 OK
  using namespace X;
  i=100;
  cout &lt;&lt; "X::i " &lt;&lt; i &lt;&lt; endl;   // prints 100 OK. 
  cout &lt;&lt; "X::i " &lt;&lt; X::i &lt;&lt; endl; // prints 10 why ?
}

main(){
  using namespace X;
  i=10;
  f();
  cout &lt;&lt; "X::i " &lt;&lt; i &lt;&lt; endl; //prints 10 why ?
}
</code></pre>

<p>Thanks for any help to make me understand this.</p>
