Reputation: 23
I am getting errors like:
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
In FxMathFunctions.h I have:
11: struct FxPoint2d;
12:
13: inline FxInt32 IMin(FxInt32 i1,FxInt32 i2)
14: {
15: if (i2 < i1) i1 = i2;
16: return i1;
17: }
FxInt32 is defined in a header that I am including as:
typedef long FxInt32;
I cant decide by the errors if it says that FxInt32 is being redefined or if the whole function is.
How do I solve this?
UPDATE I added the line numbers above.
Upvotes: 1
Views: 606
Reputation: 11991
It's saying the whole function is defined twice.
My psychic debugging powers tell me you are somehow recursively including that header, and that header doesn't have a proper guard against this happening. Thus the inline function is defined twice.
Upvotes: 1
Reputation: 231433
It's hard to say without knowing what's on lines 13 and 15 of FxMathFunctions.h. That said, keep in mind that C++ has a built-in std::min
and std::max
in <algorithm>
, and they work for all comparable types.
Upvotes: 0
Reputation: 36092
Move the function definition into a .cpp file and just have the prototype in the .h file. Let the compiler worry about the optimization
Upvotes: 0