title: Namespace and static class members linking
body: <p>Lets say I have two files: </p>
  
  <pre><code>/**
   * class.cpp
   */ 
  #include &lt;stdio.h&gt;
  class foo 
  {
  private:
          int func();
  };
  
  int foo::func(void)
  {
          printf("[%s:%d]: %s\n", __FILE__, __LINE__, __FUNCTION__);
          return -1; 
  }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>/**
   * main.cpp
   */ 
  #include &lt;stdio.h&gt;
  namespace foo 
  {
          int func(void);
  }
  int main(void)
  {
          int ret = foo::func();
          printf("[%s:%d]: ret=%d\n", __FILE__, __LINE__, ret);
          return 0;
  }
  </code></pre>
  
  <p>compiled as follows:</p>
  
  <pre><code>g++ -o a.out main.cpp class.cpp 
  </code></pre>
  
  <p>There is an output from executable file:</p>
  
  <pre><code>[class.cpp:15]: func
  [main.cpp:14]: ret=-1
  </code></pre>
  
  <p>And finally my question:</p>
  
  <p>Why is this sample code compiled without any errors and we are able to invoke <b>private</b> method of <b>class foo</b> ?</p>
  
  <p>Compiled with gcc 4.6.3 but not only.
  I know that the compiler does not distinguish those two symbols (<b>func</b> function from namespace <b>foo</b> and private function <b>foo</b> from <b>class foo</b>). Output from <b>nm</b>:</p>
  
  <pre><code>nm class.o
  00000000 T _ZN3foo4funcEv
  00000017 r _ZZN3foo4funcEvE12__FUNCTION__
           U printf
  
  nm main.o
           U _ZN3foo4funcEv
  00000000 T main
           U printf
  </code></pre>
  
  <p>I would like to ask whether this behavior is correct or not? IMHO this is not correct behavior and it is not safe at all (breaks down encapsulation).</p>
  
  <p>I would like to mention that compiler from visual studio 2008 does not link those two symbols.</p>