1

我收到如下错误:

FxMathFunctions.h: In function 'FxInt32 IMin(FxInt32, FxInt32)':

FxMathFunctions.h:13: error: redefinition of 'FxInt32 IMin(FxInt32, FxInt32)'

FxMathFunctions.h:15: error: 'FxInt32 IMin(FxInt32, FxInt32)' previously defined here

在 FxMathFunctions.h 我有:

11: struct FxPoint2d;
12:
13: inline FxInt32 IMin(FxInt32 i1,FxInt32 i2)
14: {
15:    if (i2 < i1) i1 = i2;
16:    return i1;
17: }

FxInt32 在我包含的标头中定义为:

typedef long                FxInt32;

如果它说 FxInt32 正在被重新定义或者整个函数是否被重新定义,我无法通过错误来决定。

我该如何解决这个问题?

更新我添加了上面的行号。

4

3 回答 3

1

这就是说整个函数被定义了两次。

我的心理调试能力告诉我,您以某种方式递归地包含该标头,并且该标头没有适当的防范措施来防止这种情况发生。因此内联函数被定义了两次。

于 2010-06-23T04:48:43.743 回答
0

将函数定义移动到 .cpp 文件中,然后将原型放在 .h 文件中。让编译器担心优化

于 2010-06-23T04:31:34.910 回答
0

如果不知道 FxMathFunctions.h 的第 13 和 15 行是什么,很难说。也就是说,请记住 C++ 具有内置的std::minstd::maxin <algorithm>,它们适用于所有可比较的类型。

于 2010-06-23T04:33:32.617 回答