Cython:'+'的操作数类型无效(btVector3; btVector3)

时间:2013-05-05 10:59:10

标签: cython

bullet.pxd:

cdef extern from "bullet/LinearMath/btVector3.h":
    cdef cppclass btVector3:
        btVector3(float, float, float) except +
        btVector3 operator+(const btVector3&, const btVector3&)

btmath.pyx:

cimport bullet as bt

cdef class Vector:

    cdef bt.btVector3* _this

    def __cinit__(self, float x=0, float y=0, float z=0):

        self._this = new bt.btVector3(x, y, z)


    def __add__(Vector self, Vector other):

        vec = Vector()
        del vec._this
        vec._this[0] = self._this[0] + other._this[0]

        return vec

btVector3.h中operator +的原型:

SIMD_FORCE_INLINE btVector3 
operator+(const btVector3& v1, const btVector3& v2);

如标题所述,我得到“'''(btVector3; btVector3)的无效操作数类型”。我猜它有一些关于Cython如何处理传递引用的东西,可能吗?

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:2)

事实证明,在这种情况下,Cython将“this”参数视为隐式,因此bullet.pxd应如下所示:

cdef extern from "bullet/LinearMath/btVector3.h":
    cdef cppclass btVector3:
        btVector3(float, float, float) except +
        btVector3 operator+(btVector3)

非常感谢Robert Bradshaw,帮助我解决这个问题:https://groups.google.com/forum/#!topic/cython-users/8LtEE_Nvf0o