I am a newbie to Cython. I am trying to create a Cython wrapper for Python of the following C++ code example. The example below is just a mocked up example which illustrates what I am doing in my project and the issue I am having.
C++ class
A.h
class A {
public:
A();
B * newB(){
return new B(this, "");
}
};
B.h
class B {
public:
B(A * a, const char * cwd);
};
In Cython:
classes.pxd file:
cdef extern from "A.h":
cdef cppclass A:
A() except +
B * newB()
// Both classes in same .pxd file
cdef extern from "B.h":
classes.pyx file:
cimport classes
from libcpp cimport bool
cdef class PyA:
cdef classes.A *thisptr
def __cinit__(self):
self.thisptr = new classes.A()
def newB(self):
cdef PyB val = PyB()
val.thisxptr = classes.newB()
return val
cdef class PyB:
cdef classes.B *thisxptr
def __cinit__(self):
self.thisxptr = NULL
def __dealloc__(self):
if self.thisxptr != NULL:
del self.thisxptr
In summary class B
should be created via the newB()
method in class A
, mainly because class A
certain key properties and resources which class B
will need. But I am getting the following error:
Cannot convert Python object to 'B *'