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
?
在此先感謝。
爲了澄清,問題不在於'const'和'inline'的混合(我一直這樣做),但是'inline'必須在頭文件中。 –
按照你所說的,g ++只是引發了另一個警告:'warning:內聯函數'void Point3f :: project2D(ProjType,const Point2i&)const'使用但從未定義過[默認啓用] –
@ComboZhc不要把在.cpp文件中的所有功能。把*只*放在標題中。 –