title: Codeblocks c++ undefined reference error, class is defined
body: <p>Hey guys I asked a question the other day about some c++ code that I couldn't get to work. I took everyones advice as to how to create objects in c++ but now I get undefined reference errors. I am using the latest code blocks version and using that to compile. I have read that this is caused by not linking some files during compilation, and that it means I have defined the class in the header file but not in the code, which confuses me because from my understanding (a profs example) I am declaring the objects.</p>
  
  <p>Header File 
  MathObject.h</p>
  
  <pre><code>class MathObject{
  private:
      int num1;
      int num2;
  
  public:
      int sum();
      MathObject(int n, int m);
  };
  </code></pre>
  
  <p>MathObject file
  MathObject.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "MathObject.h"
  using namespace std;
  
  MathObject :: MathObject(int n, int m){
      num1 = n;
      num2 = m;
  }
  
  int MathObject :: sum(){
      return num1+num2;
  }
  </code></pre>
  
  <p>Main File</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "MathObject.h"
  using namespace std;
  
  int main(int args, char *argv[]){
      MathObject *mo = new MathObject(3,4);
      int sum = mo -&gt; sum();
  
      MathObject mo2(3,4);
  
      //cout &lt;&lt; sum &lt;&lt; endl;
      return 0;
  }
  </code></pre>
  
  <p>The undefined reference is for all calls to anything in the MathObject class, I have been searching for a small c++ example that I can understand. (The syntax is so different from java)</p>
  
  <p>This used to happen when I tried to use multiple files in c, could this be an issue with my computer?</p>