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

问题描述 投票:0回答:1

我试图复制一些C ++代码使用Python在Python会自动调用与升压定义的C ++函数。

我的问题就来了这里原有的C ++代码是指虚拟功能。

虚拟功能与NO_INIT例如定义

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

如果我尝试和Python的使用他们,我让他们不能从蟒蛇被称为错误消息。

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

即,因为NO_INIT定义,这意味着没有构造的。

所以我的问题是怎么一个应该使用C ++虚函数在Python。

我见过https://www.boost.org/doc/libs/1_55_0/libs/python/doc/tutorial/doc/html/python/exposing.html#python.class_virtual_functions

但是,这似乎是有关重写虚函数与蟒蛇。

升压是1.65.1版本,我只是碰巧找到升压并提到1.55虚函数的一些文档。我不知道它有虚函数交易的方式发生了变化。

我试图建立一个FreeCAD工作台,并同时FreeCAD是在迁移到Python 3 Python的由每日更新所使用的版本的过程是Python版本:2.7.15rc1。

不知道类的氧文件是最新的版本,但在G4VPhysicalVolume是http://www.apc.univ-paris7.fr/~franco/g4doxy/html/classG4VPhysicalVolume.html记录。升压定义是我原来的职位。

为了提供一个完整的,可核查的例子是不可能的,而不需要有人来下载和从源代码编译两FreeCAD和GEANT4

python c++ python-2.7 boost
1个回答
0
投票

好吧,我发现我可以创建G4PVPlacment物理卷。

© www.soinside.com 2019 - 2024. All rights reserved.