title: errors when compiling class in c++
body: <p>I tried to create a class for 3-D vector in c++, but there are some errors. I have learnt a little bit of oop in python before, but I'm still pretty new to oop and c++. I created the header file threevector.h, the file for the class threevector.cpp and the main program file main.cpp. I just want to know what I have done wrong.</p>
  
  <pre><code>// threevector.h
  #ifndef THREEVECTOR_H
  #define THREEVECTOR_H
  #include &lt;iostream&gt;
  
  class threevector {
      private:
          double xcoord, ycoord, zcoord;
  
      public:
          threevector();
          threevector(double x, double y, double z, char type);
          void print ();      
  };
  #endif // THREEVECTOR_H
  
  
  //threevector.cpp
  #include "threevector.h"
  #include &lt;cmath&gt;
  
  threevector() {
      xcoord = 0.0;
      ycoord = 0.0;
      zcoord = 0.0;
  }
  
  threevector(double x, double y, double z, char type) {
      if (type == 'c') {
          // cartesian coordinate
          xcoord = x;
          ycoord = y;
          zcoord = z;
      } 
      else if (type == 'p') {
          // polar coordinate
          // x = r, y = phi, z = theta
          xcoord = x*sin(y)*cos(z);
          ycoord = x*sin(y)*sin(z);
          zcoord = x*cos(y);
          }
  }
  
  void print () {
      std::cout &lt;&lt; xcoord &lt;&lt; '\t' &lt;&lt; ycoord &lt;&lt; '\t' &lt;&lt; zcoord &lt;&lt; std::endl;
  }
  
  
  // main.cpp
  #include "threevector.h"
  #include &lt;cmath&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  
  int main() {
      threevector v0;
      v0.print();
  
      threevector v1(-1,2,4.384,'c');
      cout &lt;&lt; "v1 = ";
      v1.print();
  
      return 0;
  }
  </code></pre>
  
  <p>The following are the error messages I get:</p>
  
  <pre><code>main.cpp(.text+0x15): undefined reference to 'threevector::threevector()'
  main.cpp(.text+0x15): undefined reference to 'threevector::print()'
  main.cpp(.text+0x15): undefined reference to 'threevector::threevector::threevector(double, double, double, char)'
  main.cpp(.text+0x15): undefined reference to 'threevector::print()'
  [Error] ld returned 1 exit status
  </code></pre>