title: C++ multiple definition errors in 3-way header include
body: <p>I have 3 header files defining objects:</p>
  
  <p>Point3d.h</p>
  
  <pre><code>#ifndef POINT3D_H
  #define POINT3D_H
  
  class Ray3d;
  class Vector3d;
  #include "Ray3d.h"
  #include "Vector3d.h"
  
  
  class Point3d {
       ...
  };
  #endif
  </code></pre>
  
  <p>Vector3d.h</p>
  
  <pre><code>#ifndef VECTOR3D_H
  #define VECTOR3D_H
  
  
  class Point3d;
  class Ray3d;
  
  #include "Ray3d.h"
  #include "Point3d.h"
  
  
  class Vector3d {
      ...
  
  };
  
  #endif
  </code></pre>
  
  <p>and Ray3d.h</p>
  
  <pre><code>#ifndef RAY3D_H
  #define RAY3D_H
  
  
  class Point3d;
  class Vector3d;
  
  #include "Point3d.h"
  #include "Vector3d.h"
  
  
  class Ray3d {
      ...
  
  };
  
  #endif
  </code></pre>
  
  <p>I won't include the .cpp files, but all the functions are defined there.</p>
  
  <p>And then I have this class:
  Transform.h</p>
  
  <pre><code>#ifndef TRANSFORM_H
  #define TRANSFORM_H
  
  #include &lt;Eigen/Dense&gt;
  #include "../../geometry/Ray3d.cpp"
  #include "../../geometry/Point3d.cpp"
  #include "../../geometry/Vector3d.cpp"
  
  
  using Eigen::MatrixXd;
  
  
  class Transform {
      ...
  };
  #endif
  </code></pre>
  
  <p>AND FINALLY I have this subclass:
  Translation.h</p>
  
  <pre><code>#ifndef TRANSLATION_H
  #define TRANSLATION_H
  
  //#include &lt;Eigen/Dense&gt;
  
  #include "Transform.h"
  
  
  //#include "../../geometry/Point3d.cpp"
  //#include "../../geometry/Vector3d.cpp"
  //#include "../../geometry/Ray3d.cpp"
  
  using Eigen::MatrixXd;
  
  
  class Translation : public Transform {
      ...
  };
  #endif
  </code></pre>
  
  <p>The problem is when I try to compile Translation.cpp:</p>
  
  <pre><code>g++ Transform.cpp Translation.cpp
  </code></pre>
  
  <p>I get a multiple definition of function error for every method in Ray3d, Point3d, and Vector3d.  What can I do do avoid this?  Should I be including less?  Is my g++ command wrong?  Thanks!</p>
  
  <p>I'm also aware that I'm doing both forward declaration and includes in the first 3 headers, but that was the only way I could get those to compile.  Part of the problem maybe?</p>