python - 从python访问一个带有指针的C++函数

标签 python c++ boost

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

出现以下错误

<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/

相关文章:

python - 如何在 Komodo Edit/IDE 中设置新文件的文件类型?

python - Scrapy 跟随链接并收集电子邮件

c++ - 将四元数转换为欧拉角。 Y角度范围问题

c++ - dijkstra 最短路径算法的时间复杂度是否取决于所使用的数据结构?

c++ - boost::variant 不能同时处理 string 和 wstring

boost - 使用大小优化(-Os)编译boost_regex时出现 'duplicate section'错误

c++ - boost::asio 多线程异步接受阻塞读/写服务器

python - 为什么 NetworkX 中的 Girvan-Newman 算法这么慢

python - double for,python 中的一些错误

c++ - 成员函数上的 boost::function