代码:
点3f.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;
}
}
调用此函数会在编译时引发错误:
undefined reference to `Point3f::project2D(ProjType, Point2i const&) const'
我尝试了没有和有inline
符号的每个案例:
inline
在标题中,而不是在 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
在标题中,也在 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
不在标题中,而是在 cpp 中:
undefined reference to `Point3f::project2D(ProjType, Point2i const&) const'|
inline
不在标头中,也不在 cpp 中:
It works but that's not what I want
问题:
const and inline member function
有意义吗?- 如何申报
const and inline member function
?
提前致谢。