title: C++ Namespace member access in different files how to? how "namespace std" implemented?
body: <p>I have declared the below namespace in sample.h</p>
  
  <pre><code>// namespace with identifier
  namespace N1
  {
      int b = 80;
  }
  </code></pre>
  
  <p>sample1.cpp use the above namespace declaration</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "sample.h"
  
  using namespace std;
  using namespace N1;
  
  int main(void)
  {
      cout &lt;&lt; "b (in main) = " &lt;&lt; b &lt;&lt; endl;
        foo(); //written in sample2.cpp
        return 0;
  }
  </code></pre>
  
  <p>sample2.cpp also use the namespace declared in sample.h</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "sample.h"
  
  using namespace std;
  using namespace N1;
  
  void foo(void)
  {
      cout &lt;&lt; "b = " &lt;&lt; b &lt;&lt; endl;
  }
  </code></pre>
  
  <p>when I compiled, I got the below errors</p>
  
  <pre><code>$&gt; g++ sample1.cpp sample2.cpp
  /tmp/ccB25lEF.o:(.data+0x0): multiple definition of `N1::b'
  /tmp/cchLecEj.o:(.data+0x0): first defined here
  </code></pre>
  
  <p>Let me know how to resolve and how "<strong><em>namespace std</em></strong>" implemented to avoid this problem ?</p>