title: Multiple definition of a function error, even when using #if guard clauses
body: <p>I am creating a simple UTIL.h file contain aplusb(int, int) function for my C++ project. However I cannot compile and the error message is about multiple definition of `aplusb(int, int)'. Would you please help me correct the error or give me some hints?</p>
  
  <p>I attach here my project for your detail reference. </p>
  
  <p>File UTIL.h</p>
  
  <pre><code>#ifndef UTIL_H_
  #define UTIL_H_
  
  int aplusb(int a, int b) {
      return a + b;
  }
  
  #endif /* UTIL_H_ */
  </code></pre>
  
  <p>File ClassA.h </p>
  
  <pre><code>#ifndef CLASSA_H_
  #define CLASSA_H_
  
  class ClassA {
  public:
      ClassA();
      virtual ~ClassA();
  private:
      int sum;
  };
  
  #endif /* CLASSA_H_ */
  </code></pre>
  
  <p>File ClassA.cpp</p>
  
  <pre><code>#include "ClassA.h"
  #include "UTIL.h"
  
  ClassA::ClassA() {
      // TODO Auto-generated constructor stub
      sum = aplusb(3,5);
  
  }
  
  ClassA::~ClassA() {
      // TODO Auto-generated destructor stub
  }
  </code></pre>
  
  <p>File ClassB.h</p>
  
  <pre><code>#ifndef CLASSB_H_
  #define CLASSB_H_
  
  class ClassB {
  public:
      ClassB();
      virtual ~ClassB();
  private:
      int sum;
  };
  
  #endif /* CLASSB_H_ */
  </code></pre>
  
  <p>File ClassB.cpp</p>
  
  <pre><code>#include "ClassB.h"
  #include "UTIL.h"
  
  ClassB::ClassB() {
      // TODO Auto-generated constructor stub
      sum = aplusb(5,6);
  }
  
  ClassB::~ClassB() {
      // TODO Auto-generated destructor stub
  }
  </code></pre>
  
  <p>Compile error message</p>
  
  <pre><code>ClassB.o: In function `aplusb(int, int)':
  /home/vtvan/Desktop/workspace/commonfunc/UTIL.h:11: multiple definition of `aplusb(int, int)'
  ClassA.o:/home/vtvan/Desktop/workspace/commonfunc/UTIL.h:11: first defined here
  collect2: error: ld returned 1 exit status
  make: *** [commonfunc] Error 1
  </code></pre>