title: C++ link error, symbol redefinition
body: <p>I came across a problem recently.</p>
  
  <p>I have three files, A.h, B.cpp, C.cpp:</p>
  
  <p>A.h</p>
  
  <pre><code>#ifndef __A_H__
  #define __A_H__
  
  int M()
  {
      return 1;
  }
  
  #endif // __A_H__
  </code></pre>
  
  <p>B.cpp</p>
  
  <pre><code>#include "A.h"
  </code></pre>
  
  <p>C.cpp</p>
  
  <pre><code>#include "A.h"
  </code></pre>
  
  <p>As I comile the three files by MSVC, there is a error:</p>
  
  <pre><code>C.obj : error LNK2005: "int __cdecl M(void)" (?M@@YAHXZ) already defined in B.obj
  </code></pre>
  
  <p>It is easy understanding, as we know, B.obj has a symbol named "M", also C.obj has a "M".
  Here the error comes.</p>
  
  <p>However, if I change M method to a class which contain a method M like this below:</p>
  
  <p>A.h</p>
  
  <pre><code>#ifndef __A_H__
  #define __A_H__
  
  class CA
  {
  public:
      int M()
      {
          return 1;
      }
  };
  
  #endif // __A_H__
  </code></pre>
  
  <p>there is no more errors!! Could somebody tell me what is happening?</p>