我正在尝试使用需要指向类的指针的函数。
出现以下错误
<class 'Boost.Python.ArgumentError'>: Python argument types in
G4TessellatedSolid.AddFacet(G4TessellatedSolid, G4TriangularFacet)
did not match C++ signature:
AddFacet(G4TessellatedSolid {lvalue}, G4VFacet*)
G4TesselledSolid 有一个函数 G4bool AddFacet (G4VFacet *aFacet)
G4TriansularFacet 类定义有 G4TriangularFacet 类:公共(public) G4VFacet
我的 Boost 类定义看起来像
class_<G4TessellatedSolid, G4TessellatedSolid*, boost::noncopyable>
("G4TessellatedSolid", "solid class")
// ---
.def("AddFacet", &G4TessellatedSolid::AddFacet)
// operators
.def(self == self)
;
我的 Python 看起来像 镶嵌 = G4TessellatedSolid() tessellate.AddFacet(面)
最佳答案
感谢引用能够通过在定义中添加碱基来解决
class_<G4VFacet, G4VFacet*, boost::noncopyable>
("G4VFacet", "solid class", no_init)
// ---
.def("SetVertex", &G4TriangularFacet::SetVertex)
// operators
.def(self == self)
;
class_<G4TriangularFacet, bases<G4VFacet> , boost::noncopyable>
("G4TriangularFacet", "solid class")
// ---
.def("SetVertex", &G4TriangularFacet::SetVertex)
// operators
.def(self == self)
;
关于python - 从python访问一个带有指针的C++函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54224743/