【问题标题】:Accessing from python a C++ function that takes a pointer从 python 访问一个带有指针的 C++ 函数
【发布时间】:2019-01-16 20:19:38
【问题描述】:

我正在尝试使用一个需要指向类的指针的函数。

我收到以下错误

<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 : 公共 G4VFacet

我的 Boost 类定义看起来像

class_<G4TessellatedSolid, G4TessellatedSolid*, boost::noncopyable>
         ("G4TessellatedSolid", "solid class")
 // ---
       .def("AddFacet",       &G4TessellatedSolid::AddFacet)
 // operators
       .def(self == self)
       ;

我的蟒蛇看起来像 tessellate = G4TessellatedSolid() tessellate.AddFacet(人脸)

【问题讨论】:

标签: python c++ boost


【解决方案1】:

感谢参考 可以通过在定义中添加碱基来解决

 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)
   ;

【讨论】:

    猜你喜欢
    • 2010-12-17
    • 1970-01-01
    • 1970-01-01
    • 2013-10-13
    • 2010-12-04
    • 1970-01-01
    • 2018-01-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多