簡體   English   中英

從Python使用boost定義的C ++虛擬函數

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

我試圖用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 ++虛擬函數。

我已經看到https://www.boost.org/doc/libs/1_55_0/libs/python/doc/tutorial/doc/html/python/exposed.html#python.class_virtual_functions

但這似乎與用python覆蓋虛擬函數有關。

Boost是1.65.1版本,我剛巧找到了關於Boost和虛函數的文檔,它們都引用了1.55。 我不確定它處理虛擬功能的方式是否已更改。

我正在嘗試開發FreeCAD工作台,而FreeCAD正在遷移到Python 3的過程中,每日更新使用的Python版本是Python版本:2.7.15rc1。

不知道類的氧文件是最新的版本,但在G4VPhysicalVolume是記錄http://www.apc.univ-paris7.fr/~franco/g4doxy/html/classG4VPhysicalVolume.html boost的定義是我的原始帖子。

要提供完整且可驗證的示例,必須先要求別人從FreeCAD和Geant4處下載並進行構建。

好的,我發現可以使用G4PVPlacment創建物理卷。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM