【发布时间】:2012-10-17 17:47:32
【问题描述】:
代码:
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;
}
}
调用此函数会在编译时引发错误:
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?
提前致谢。
【问题讨论】: