/* I'm getting errors I don't understand with this code: (never mind the linker errors, I guess they're the result of the above warnings, but I don't know why the warnings are occurring) The compiler commandline is: c++ test_point.cpp point.cpp -o test_point Errors: point.h:23: warning: inline function ‘float gfx::point::x() const’ used but never defined point.h:26: warning: inline function ‘float gfx::point::y() const’ used but never defined point.h:17: warning: inline function ‘gfx::point& gfx::point::x(float)’ used but never defined point.h:20: warning: inline function ‘gfx::point& gfx::point::y(float)’ used but never defined point.h:30: warning: inline function ‘bool gfx::point::operator!=(const gfx::point&) const’ used but never defined point.h:29: warning: inline function ‘bool gfx::point::operator==(const gfx::point&) const’ used but never defined /tmp/ccI5jwDk.o: In function `main': test_point.cpp:(.text+0xa8): undefined reference to `gfx::point::x() const' test_point.cpp:(.text+0x13c): undefined reference to `gfx::point::y() const' test_point.cpp:(.text+0x1d5): undefined reference to `gfx::point::x(float)' test_point.cpp:(.text+0x1dd): undefined reference to `gfx::point::x() const' test_point.cpp:(.text+0x27a): undefined reference to `gfx::point::y(float)' test_point.cpp:(.text+0x282): undefined reference to `gfx::point::y() const' test_point.cpp:(.text+0x33a): undefined reference to `gfx::point::operator!=(gfx::point const&) const' test_point.cpp:(.text+0x3c4): undefined reference to `gfx::point::x(float)' test_point.cpp:(.text+0x3d7): undefined reference to `gfx::point::y(float)' test_point.cpp:(.text+0x3e9): undefined reference to `gfx::point::operator==(gfx::point const&) const' */ // point.h #include "point.h" namespace gfx { point& point::x(float ax) { cx = ax; return *this; } point& point::y(float ay) { cy = ay; return *this; } float point::x() const { return cx; } float point::y() const { return cy; } bool point::operator==(const point& other) const { return ((other.x() == x()) && (other.y() == y())); } bool point::operator!=(const point& other) const { return ((other.x() != x()) || (other.y() != y())); } } // point.cpp #ifndef POINT_H #define POINT_H namespace gfx { class point { protected: /* coordinate x */ float cx; /* coordinate y */ float cy; public: /** Constructor for the point. * @param ax the point x. * @param ay the point y. */ point(float ax, float ay) :cx(ax), cy(ay) {} /* setter for x */ inline point& x(float ax); /* setter for y */ inline point& y(float ay); /* getter for x */ inline float x() const; /* getter for y */ inline float y() const; /* operators */ inline bool operator==(const point& other) const; inline bool operator!=(const point& other) const; /* virtual destructor */ virtual ~point(){} }; } #endif // test_point.cpp #include "point.h" #include "../test_macros.h" int main(int argc, char** argv) { gfx::point a(2,1); TEST(a.x() == 2, "Testing x getter") TEST(a.y() == 1, "Testing y getter") TEST(a.x(3).x() == 3, "Testing x setter") TEST(a.y(4).y() == 4, "Testing y setter") gfx::point b(2,1); TEST(a != b, "Testing operator!=") a.x(2).y(1); TEST(a == b, "Testing operator==") return 0; }