У меня есть два класса (допустим, самые простые, реализация не важна). Мой defs.pxd
файл (с Cython DEFS) выглядит следующим образом:Способ передачи объекта C++ методу другого объекта в cython
cdef extern from "A.hpp":
cdef cppclass A:
A() except +
cdef extern from "B.hpp":
cdef cppclass B:
B() except +
int func (A)
Мой pyx
файл (с питона DEFS) выглядит следующим образом:
from cython.operator cimport dereference as deref
from libcpp.memory cimport shared_ptr
cimport defs
cdef class A:
cdef shared_ptr[cquacker_defs.A] _this
@staticmethod
cdef inline A _from_this(shared_ptr[cquacker_defs.A] _this):
cdef A result = A.__new__(A)
result._this = _this
return result
def __init__(self):
self._this.reset(new cquacker_defs.A())
cdef class B:
cdef shared_ptr[cquacker_defs.B] _this
@staticmethod
cdef inline B _from_this(shared_ptr[cquacker_defs.B] _this):
cdef B result = B.__new__(B)
result._this = _this
return result
def __init__(self):
self._this.reset(new cquacker_defs.B())
def func(self, a):
return deref(self._this).func(deref(a._this))
Дело в том, что deref(self._this)
работает право, но deref(a._this)
Безразлично» т с этой ошибкой:
Invalid operand type for '*' (Python object)
Как я могу передать внутренний C один Python объекта ++ объект в метод другого своего в python?