运算符重载的冲突类型(XCode 5.0)

时间:2013-09-19 12:59:34

标签: c++ ios xcode operator-overloading conflict

自从更新到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-'

我该怎么做才能解决这个问题?

0 个答案:

没有答案