2

自从更新到 XCode 5.0 后,我的 C++ 数学库中的一段代码已经停止工作。

它声明了一些运算符重载函数,这些函数根据传递的参数类型做出不同的响应。这是代码(全部在 .h 文件中):

#ifndef __RMKit__RMVector3f__
#define __RMKit__RMVector3f__

#include <stdbool.h>
#include <math.h>

#ifdef __cplusplus
extern "C" {//start extern "C"
#endif

union _RMVector3f {
    struct {float x,y,z;};
    struct {float r,g,b;};
    struct {float s,t,p;};
    float v[3];
};
typedef union _RMVector3f RMVector3f;

#pragma mark - math operator overloads prototypes
#ifdef __cplusplus //only declare operator overloads if using C++
static __inline__ RMVector3f operator + (RMVector3f lhs, RMVector3f rhs);
static __inline__ RMVector3f operator + (RMVector3f lhs, float rhs);
static __inline__ RMVector3f operator - (RMVector3f lhs, RMVector3f rhs);
static __inline__ RMVector3f operator - (RMVector3f lhs, float rhs);

#pragma mark - math operator overload implementations
static __inline__ RMVector3f operator + (RMVector3f lhs, RMVector3f rhs)
{
    RMVector3f tmp;
    tmp.x = lhs.x+rhs.x;
    tmp.y = lhs.y+rhs.y;
    tmp.z = lhs.z+rhs.z;
    return tmp;
}

static __inline__ RMVector3f operator + (RMVector3f lhs, float rhs)
{
    RMVector3f tmp;
    tmp.x = lhs.x+rhs;
    tmp.y = lhs.y+rhs;
    tmp.z = lhs.z+rhs;
    return tmp;
}

static __inline__ RMVector3f operator - (RMVector3f lhs, RMVector3f rhs)
{
    RMVector3f tmp;
    tmp.x = lhs.x-rhs.x;
    tmp.y = lhs.y-rhs.y;
    tmp.z = lhs.z-rhs.z;
    return tmp;
}

static __inline__ RMVector3f operator - (RMVector3f lhs, float rhs)
{
    RMVector3f tmp;
    tmp.x = lhs.x-rhs;
    tmp.y = lhs.y-rhs;
    tmp.z = lhs.z-rhs;
    return tmp;
}
#endif

#ifdef __cplusplus
}//end extern "C"
#endif

#endif /* defined(__RMKit__RMVector3f__) */

编译器(LLVM 5.0)给了我错误,例如:

Conflicting types for 'operator+'
Conflicting types for 'operator-'

我能做些什么来解决这个问题?

4

0 回答 0