C++ multiple definition errors in 3-way header include -
i have 3 header files defining objects:
point3d.h
#ifndef point3d_h #define point3d_h class ray3d; class vector3d; #include "ray3d.h" #include "vector3d.h" class point3d { ... }; #endif
vector3d.h
#ifndef vector3d_h #define vector3d_h class point3d; class ray3d; #include "ray3d.h" #include "point3d.h" class vector3d { ... }; #endif
and ray3d.h
#ifndef ray3d_h #define ray3d_h class point3d; class vector3d; #include "point3d.h" #include "vector3d.h" class ray3d { ... }; #endif
i won't include .cpp files, functions defined there.
and have class: transform.h
#ifndef transform_h #define transform_h #include <eigen/dense> #include "../../geometry/ray3d.cpp" #include "../../geometry/point3d.cpp" #include "../../geometry/vector3d.cpp" using eigen::matrixxd; class transform { ... }; #endif
and have subclass: translation.h
#ifndef translation_h #define translation_h //#include <eigen/dense> #include "transform.h" //#include "../../geometry/point3d.cpp" //#include "../../geometry/vector3d.cpp" //#include "../../geometry/ray3d.cpp" using eigen::matrixxd; class translation : public transform { ... }; #endif
the problem when try compile translation.cpp:
g++ transform.cpp translation.cpp
i multiple definition of function error every method in ray3d, point3d, , vector3d. can do avoid this? should including less? g++ command wrong? thanks!
i'm aware i'm doing both forward declaration , includes in first 3 headers, way compile. part of problem maybe?
you should not include cpp files in transform.h
Comments
Post a Comment