简体   繁体   English

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

[英]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.

相关问题 如何为Python Swigged C ++对象创建和分配回调函数 - How to create and assign a callback function for a Python Swigged C++ object Object 在 Python 中通过 Pybind11 创建的 Object 未被 ZF6F87C3FDCF8B3C2FC2F07F 函数识别为派生的 class - Object created in Python via Pybind11 not recognized as a derived class by C++ functions 通过Python BOOST使用派生类(C ++) - Using derived class (C++) by Python BOOST 导入错误:在 python 中导入 swigged c++ 类时未定义的符号 - ImportError: undefined symbol when importing swigged c++-class in python Python:从派生类中获取基类值 - Python: Getting baseclass values from derived class 如何使用 boost/python 将 C++ 虚函数公开给 python? - How to expose C++ virtual functions to python using boost/python? 如何在baseclass方法中使用派生类变量 - How to use derived class variable in baseclass method 如何使用QT / python从Javascript调用C ++函数? - how to invoke C++ functions from Javascript using QT/python? 如何创建一个界面,允许我访问使用 python 中的 MFC 实现的 C++ 中的按钮(和其他 ui)功能? - How do I create an interface that allows me to access button(and other ui) functions in C++ implemented using MFC from python? 如何使用Python访问属于对象的动态C ++数组变量? - How to access dynamic C++ array variable, belonging to an object, with Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM