简体   繁体   English

Cython中的C ++指针

[英]C++ pointers in Cython

I use Cython to wrap my C++ classes. 我用Cython包装我的C ++类。 Some of methods return sth. 一些方法返回某物。 like class_name* . 就像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 ). class_name可能是pxd和pyx文件中已经描述过的一些复杂类(就像在扩展答案https://stackoverflow.com/a/39116733/4881441中在此处提到的那样)。 But Cython says in pyx defs that I am returning not a Python type. 但是Cython在pyx defs中说我返回的不是Python类型。 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. 我希望能够在python中返回类似c ++的指针,然后使用此对象的方法并将其传递给c ++方法。

You can't directly return a pointer from a def method (only from a cdef ). 您不能直接从def方法返回指针(仅从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. 您需要编写一个Cython Wrapper类,该类存储要传递的指针,并且您可以返回此Wrapper对象。 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. 如果要在C ++对象上执行方法,则还必须使用Cython包装器并将方法调用委托给存储的实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM