函数指针的数组在链接时找不到函数实现

jiandingzhe 2012-09-13 03:46:57
我有一个类成员,它是一个函数指针的数组,里面存储若干个函数的地址:
头文件:

typedef unsigned char (*support_point_func)(const Shape& shape, const VectorF& n, VectorF& result);

unsigned char support_sphere (const Shape& shape, const VectorF& n, VectorF& result);
unsigned char support_box (const Shape& shape, const VectorF& n, VectorF& result);
unsigned char support_cylinder (const Shape& shape, const VectorF& n, VectorF& result);
unsigned char support_capsule (const Shape& shape, const VectorF& n, VectorF& result);
unsigned char support_convex_hull(const Shape& shape, const VectorF& n, VectorF& result);
unsigned char support_complex (const Shape& shape, const VectorF& n, VectorF& result);

class Shape
{
static support_point_func support_point_func_table[];
}



实现文件:

unsigned char support_sphere(const Shape& shape, const VectorF& n, VectorF& result)
{
}

unsigned char support_box(const Shape& shape, const VectorF& n, VectorF& result)
{
}

unsigned char support_cylinder(const Shape& shape, const VectorF& n, VectorF& result)
{
}

unsigned char support_capsule(const Shape& shape, const VectorF& n, VectorF& result)
{
}

unsigned char support_convex_hull(const Shape& shape, const VectorF& n, VectorF& result)
{
}

unsigned char support_complex(const Shape& shape, const VectorF& n, VectorF& result)
{
}

support_point_func Shape::support_point_func_table[] =
{
&support_sphere,
&support_box,
&support_cylinder,
&support_capsule,
&support_convex_hull,
&support_complex
};


最终会在链接时,声称找不到那些函数。这是为什么?
...全文
63 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
jiandingzhe 2012-09-14
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

这样就可以了:
C/C++ code

class Shape;
struct VectorF;

typedef unsigned char (*support_point_func)(const Shape& shape, const VectorF& n, VectorF& result);

unsigned char support_sphere (……
[/Quote]
后来发现是名字空间的问题,我没在主楼里写出来。
图灵狗 2012-09-14
  • 打赏
  • 举报
回复
这样就可以了:

class Shape;
struct VectorF;

typedef unsigned char (*support_point_func)(const Shape& shape, const VectorF& n, VectorF& result);

unsigned char support_sphere (const Shape& shape, const VectorF& n, VectorF& result);
unsigned char support_box (const Shape& shape, const VectorF& n, VectorF& result);
unsigned char support_cylinder (const Shape& shape, const VectorF& n, VectorF& result);
unsigned char support_capsule (const Shape& shape, const VectorF& n, VectorF& result);
unsigned char support_convex_hull(const Shape& shape, const VectorF& n, VectorF& result);
unsigned char support_complex (const Shape& shape, const VectorF& n, VectorF& result);

class Shape
{
static support_point_func support_point_func_table[];
};
bluesky0318 2012-09-14
  • 打赏
  • 举报
回复
你既然已经用typedef定义了函数指针类型,怎么后面又把函数重新定义呢?很奇怪的用法

64,636

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧