Code:
point3f.h
Class Point3f {
...
inline void project2D(ProjType p, const Point2i& view) const;
};
point3f.cpp
inline void Point3f::project2D(ProjType p, const Point2i& view) const {
switch(p) {
case PROJ_XY:
glVertex2f(x * view.x, y * view.y);
break;
case PROJ_YZ:
glVertex2f(y * view.x, z * view.y);
break;
case PROJ_XZ:
glVertex2f(x * view.x, z * view.y);
break;
default:
break;
}
}
Calling this function raises an error in compile time:
undefined reference to `Point3f::project2D(ProjType, Point2i const&) const'
I tried every case without and with inline
symbol:
inline
in header, not in cpp:
Warning: inline function ‘void Point3f::project2D(ProjType, const Point2i&) const’ used but never defined [enabled by default
undefined reference to `Point3f::project2D(ProjType, Point2i const&) const'|
inline
in header, also in cpp:
Warning: inline function ‘void Point3f::project2D(ProjType, const Point2i&) const’ used but never defined [enabled by default
undefined reference to `Point3f::project2D(ProjType, Point2i const&) const'|
inline
not in header, but in cpp:
undefined reference to `Point3f::project2D(ProjType, Point2i const&) const'|
inline
not in header, neither in cpp:
It works but that's not what I want
Question:
- Does
const and inline member function
make sense? - How to declare a
const and inline member function
?
Thanks in advance.
The function being
const
has nothing to do with it. If you want itinline
, you must define it in the header file instead of inpoint3f.cpp
. Example:In this case, the
inline
keyword is not needed at all. If you define the function inside the class definition,inline
is the default. But you can still specify it, if you want (as I've done in the above example.)