찾다

 >  Q&A  >  본문

链接 - c++函数指针奇怪的错误,为什么

//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; }也通过了,我把那个函数指针换成其他函数也没问题,求解

天蓬老师天蓬老师2806일 전539

모든 응답(1)나는 대답할 것이다

  • PHP中文网

    PHP中文网2017-04-17 13:18:10

    找到说明了,,内联函数要定义在头文件中。。。。
    编译时内联展开,不会产生函数,所以提示未定义的符号

    회신하다
    0
  • 취소회신하다