如何使用衍生的Python swigged对象访问C++基类函数?

2024-10-03 02:48:16 发布

您现在位置:Python中文网/ 问答频道 /正文

<我有一个C++类,比如说B,它是从另一个类中公开的,A.

B类在Python中是swiged并可访问的。 这很好用,而且在类B中定义的所有公共函数都可以在Python中使用,几乎不需要任何工作。在

但是,在Python中创建B对象时,在类a中定义的公共函数似乎没有公开,可以自动使用。在

问题是,如何获得一个C++类类的函数,用于一个SpyGythyPython对象?在


Tags: 对象函数定义swiged类类spygythypython
2条回答

你应该不用再费劲了。以下是来自http://www.swig.org/Doc1.3/Python.html#Python_nn21的一些文档。在

31.3.8 C++ inheritance

SWIG is fully aware of issues related to C++ inheritance. Therefore, if you have classes like this

class Foo {
...
};

class Bar : public Foo {
...
};

those classes are wrapped into a hierarchy of Python classes that reflect the same inheritance structure. All of the usual Python utility functions work normally:

答案似乎是swig接口文件中include文件的实际顺序。在

通过将基类头放在派生类之前,一切似乎都按预期开始工作。在

对任何人来说,看到警告

warning 401: 'AnObjectXXX' must be defined before it is used as a base class.

将提供一个没有预期基类功能的python对象。在

相关问题 更多 >