简体   繁体   English

从Python使用boost定义的C ++虚拟函数

[英]Using boost defined C++ Virtual functions from Python

I am trying to replicate some C++ code with Python where the python calls C++ functions defined with boost. 我试图用Python复制一些C ++代码,其中python调用boost定义的C ++函数。

My problem comes where the original C++ code refers to a Virtual function. 我的问题来自原始C ++代码引用虚函数的地方。

The virtual functions are defined with no_init eg 虚函数用no_init定义,例如

 class_<G4VPhysicalVolume, G4VPhysicalVolume*, boost::noncopyable>
     ("G4VPhysicalVolume", "physical volume class", no_init)
     // ---

If I try and use them from Python I get the error message that they cannot be called from python. 如果我尝试从Python使用它们,则会收到错误消息,指出无法从python调用它们。

   <type 'exceptions.RuntimeError'>: This class cannot be instantiated from Python

ie because of the no_init definition that means no constructors. 即由于no_init定义意味着没有构造函数。

So my question is how is one supposed to use C++ Virtual functions from Python. 所以我的问题是应该如何使用Python的C ++虚拟函数。

I have seen https://www.boost.org/doc/libs/1_55_0/libs/python/doc/tutorial/doc/html/python/exposing.html#python.class_virtual_functions 我已经看到https://www.boost.org/doc/libs/1_55_0/libs/python/doc/tutorial/doc/html/python/exposed.html#python.class_virtual_functions

But this seems to be about overiding virtual functions with python. 但这似乎与用python覆盖虚拟函数有关。

Boost is version 1.65.1 I just happened to find some doc on boost and virtual functions that referred to 1.55. Boost是1.65.1版本,我刚巧找到了关于Boost和虚函数的文档,它们都引用了1.55。 I am not sure the way it deals with Virtual functions has changed. 我不确定它处理虚拟功能的方式是否已更改。

I am trying to develop a FreeCAD workbench and whilst FreeCAD is in the process of migrating to Python 3 the version of Python used by the daily update is Python version: 2.7.15rc1. 我正在尝试开发FreeCAD工作台,而FreeCAD正在迁移到Python 3的过程中,每日更新使用的Python版本是Python版本:2.7.15rc1。

Not sure the oxygen documentation of classes is the latest version but G4VPhysicalVolume is documented at http://www.apc.univ-paris7.fr/~franco/g4doxy/html/classG4VPhysicalVolume.html . 不知道类的氧文件是最新的版本,但在G4VPhysicalVolume是记录http://www.apc.univ-paris7.fr/~franco/g4doxy/html/classG4VPhysicalVolume.html The boost definition is as my original post. boost的定义是我的原始帖子。

To provided a Complete and verifiable example is not possible without requiring somebody to download and build from source both FreeCAD and Geant4 要提供完整且可验证的示例,必须先要求别人从FreeCAD和Geant4处下载并进行构建。

好的,我发现可以使用G4PVPlacment创建物理卷。

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

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