python - 使用来自 Python 的 boost 定义的 C++ 虚函数
问题描述
我正在尝试使用 Python 复制一些 C++ 代码,其中 python 调用使用 boost 定义的 C++ 函数。
我的问题出现在原始 C++ 代码指的是虚拟函数的地方。
虚函数是用 no_init 定义的,例如
class_<G4VPhysicalVolume, G4VPhysicalVolume*, boost::noncopyable>
("G4VPhysicalVolume", "physical volume class", no_init)
// ---
如果我尝试从 Python 中使用它们,我会收到无法从 python 调用它们的错误消息。
<type 'exceptions.RuntimeError'>: This class cannot be instantiated from Python
即因为 no_init 定义意味着没有构造函数。
所以我的问题是应该如何使用 Python 中的 C++ 虚拟函数。
但这似乎是关于用 python 覆盖虚函数。
Boost 是 1.65.1 版,我碰巧找到了一些关于 1.55 的 boost 和虚函数的文档。我不确定它处理虚拟功能的方式是否发生了变化。
我正在尝试开发一个 FreeCAD 工作台,虽然 FreeCAD 正在迁移到 Python 3,但每日更新使用的 Python 版本是 Python 版本:2.7.15rc1。
不确定类的氧气文档是最新版本,但 G4VPhysicalVolume 记录在http://www.apc.univ-paris7.fr/~franco/g4doxy/html/classG4VPhysicalVolume.html。提升定义是我的原始帖子。
如果不要求有人从 FreeCAD 和 Geant4 的源代码下载和构建,就不可能提供完整且可验证的示例
解决方案
好的,我发现我可以使用 G4PVPlacment 创建物理卷。
推荐阅读
- php - Laravel 7如何在对boostrap模态对话框窗口进行错误验证时重定向回来并在单击提交时保持模态
- python - pip install -r requirements.txt 错误,即使路径正确
- node.js - 静音命令中出现很多错误!(不和谐.js)
- typescript - typescript :类型检查作为参数传递的函数中的可选参数
- javascript - 如何在 if 条件下使用 reduce
- c# - 如何根据 C# 中另一列的值比较返回第一列的行值?
- ruby-on-rails - 翻译缺失:ar.activerecord.errors.models.address.attributes.area.required
- ios - Swift 5 中的 SKTexture 问题 - 内存不足(IOAF 代码 8)
- ansible - 检查 Chocolatey 是否安装在 Ansible 中
- java - Java,通过套接字发送 MouseEvents,我该怎么做?