[英]How to access C++ baseclass functions using a derived Python swigged object?
I have a C++ class, say B, that is publicly derived from another class, A. 我有一个C ++类,例如B,它是从另一个类A公开地派生的。
The B class is swigged and made accessible in Python. B类被广泛使用,并且可以在Python中访问。 This works great, and all public functions defined in class B are readily available in Python without almost any work.
这很好用,并且B类中定义的所有公共函数都可以在Python中轻松使用,而几乎不需要任何工作。
However, when creating a B object in Python the public functions that are defined in class A seem not to be exposed, available automatically. 但是,在Python中创建B对象时,类A中定义的公共函数似乎不会公开,而是自动可用的。
Question is, how do one get access to functions up a C++ class hierarchy for a swigged Python object? 问题是,如何获得一个Swiged Python对象的C ++类层次结构的功能?
It seemed the answer was in the actual ordering of include files in the swig interface file. 似乎答案是在swig接口文件中包含文件的实际顺序中。
By placing the baseclass headers BEFORE derived classes, everything seemed to start working as expected. 通过在派生类之前放置基类头,一切似乎都按预期开始工作。
For anyone "swigging", seeing the warning; 对于任何“痛饮”的人,看到警告;
warning 401: 'AnObjectXXX' must be defined before it is used as a base class.
will give you a python object without expected baseclass functionality. 将为您提供一个没有预期的基类功能的python对象。
You should get that without any further effort. 您应该毫不费力地得到它。 Here's some documentation from http://www.swig.org/Doc1.3/Python.html#Python_nn21 .
这是来自http://www.swig.org/Doc1.3/Python.html#Python_nn21的一些文档。
31.3.8 C++ inheritance
31.3.8 C ++继承
SWIG is fully aware of issues related to C++ inheritance.
SWIG完全了解与C ++继承有关的问题。 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.
这些类被包装成可反映相同继承结构的Python类层次结构。 All of the usual Python utility functions work normally:
所有常用的Python实用程序功能均可正常运行:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.