Ayaz Salikhov
Ayaz Salikhov

Reputation: 171

C++ pointers in Cython

I use Cython to wrap my C++ classes. Some of methods return sth. like class_name*. class_name may be some complicated class already described in pxd and pyx file (like it is mentioned here in extended answer https://stackoverflow.com/a/39116733/4881441). But Cython says in pyx defs that I am returning not a Python type. I want to be able to return c++-like pointers in python and then use methods of this objects and to pass them to c++ methods.

Upvotes: 1

Views: 1292

Answers (1)

user2436850
user2436850

Reputation: 178

You can't directly return a pointer from a def method (only from a cdef).

You'll need to write a Cython Wrapper class that stores the pointer you want to pass and you can return this Wrapper Object. If you want to execute methods on the C++ object you also have to use your Cython Wrapper and delegate the method calls to the stored instance.

Upvotes: 2

Related Questions