//file:canvas_object.hpp
class CanvasObject
{
public:
bool switch_shape() { return switch_shape(true); }
bool switch_shape(bool order);//逆时针 or 顺时针
}
//file:canvas_object.cpp
inline bool CanvasObject::switch_shape(bool order)
{
return true;
}
//file: canvas_view.cpp
//一个静态成员
bool (CanvasObject:: *CanvasView::_ctl_callfuncs[5])() = {
&CanvasObject::move_down,
&CanvasObject::move_down,
&CanvasObject::move_left,
&CanvasObject::move_right,
&CanvasObject::switch_shape,
};
error:
Undefined symbols for architecture i386:
"CanvasObject::switch_shape(bool)", referenced from:
CanvasObject::switch_shape() in canvas_view.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我把那个函数定义中inline去掉编译就通过了,为什么呢?我试过直接让改成
bool switch_shape() { return true; }也通过了,我把那个函数指针换成其他函数也没问题,求解
I found the instructions, the inline function must be defined in the header file. . . .
Inline expansion during compilation does not generate a function, so an undefined symbol is prompted