title: Undefined reference to a class in C++
body: <p>I have a code::blocks project, called Test.cbp. It has three files, <code>main.cpp</code> in the <code>Test</code> directory, and <code>jAlg.cpp</code> and <code>jAlg.h</code>, both in the <code>jAlg</code> directory.</p>
  
  <p><strong>main.cpp</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "jAlg.h"
  
  int main(){
      jVector bob;
      jMatrix ann;
      bob.display();
      return 0;
  }
  </code></pre>
  
  <p><strong>jAlg.cpp</strong> (summary)</p>
  
  <pre><code>class jMatrix{
      public:
          //The four entries of a 2x2 square matrix:
          //[a b]
          //[c d]
          double a, b, c, d;
  
          //Constructor
          jMatrix(double a_val = 1, double b_val = 0,
                  double c_val = 0, double d_val = 1){
              a = a_val;
              b = b_val;
              c = c_val;
              d = d_val;
          }
  
          //Several other functions and operator overloads
  };
  
  class jVector{
      public:
          //The two entries of a 2D vector
          //[x]
          //[y]
          double x, y;
  
          //Constructor
          jVector(double x_val = 0,
                  double y_val = 0){
              x = x_val;
              y = y_val;
          }
  
          //Several other functions and operator overloads
  };
  
  //Several other functions
  
  //Matrix-vector multiplication
  jVector operator* (jMatrix A, jVector v){
      jVector result;
      result.x = A.a*v.x + A.b*v.y;
      result.y = A.c*v.x + A.d*v.y;
      return result;
  }
  
  //More functions
  </code></pre>
  
  <p><strong>jAlg.h</strong> (summary)</p>
  
  <pre><code>#ifndef JALG
  #define JALG
  
  double sqr(double x);
  
  class jMatrix{
      public:
          double a, b, c, d;
  
          jMatrix(double a_val = 1, double b_val = 0,
                  double c_val = 0, double d_val = 1);
  
          //more functions
  };
  
  class jVector{
      public:
          double x, y;
  
          jVector(double x_val = 0, double y_val = 0);
  
          //more functions
  };
  
  jVector operator* (jMatrix A, jVector v);
  
  #endif
  </code></pre>
  
  <p>When I build and run the project, it behaves strangely. An error is raised saying <code>undefined reference to 'jMatrix::jMatrix(double,double,double,double)'</code>. However, there is no error related to the <code>jVector::jVector</code> constructor.</p>
  
  <p>As a test I went to the <code>jAlg</code> files and commented out the <code>jVector operator* (jMatrix A, jVector v)</code> function and run the project again. This time, an error is raised for <em>both</em> <code>jMatrix::jMatrix</code> and <code>jVector::jVector</code>. For some reason, the presence of that function makes it okay to define vectors, but not matrices.</p>
  
  <p>So here's my question: why does the presence of the function <code>jVector operator* (jMatrix A, jVector v)</code> make it okay to define <code>jVector</code>s? What can I do to make it possible to define <code>jMatrix</code> objects?</p>