Boost.Python静态方法重载

2024-10-01 09:21:15 发布

您现在位置:Python中文网/ 问答频道 /正文

如何使用博斯。Python?在

class C {
 public:
  static void F(int) {}
  static void F(double) {}
};

我试过这样的方法:

^{pr2}$

但是,它在Python中引发了一个异常(SystemError: initialization of libdistributions raised unreported exception)。如果我从bp::class_中删除一个重载,那么一切都正常。我知道Boost.Python可以自动处理重载的构造函数,所以我想知道是否有类似的静态方法。在


回答

bp::class_<C>("C")
  .def("F", (void (C::*)(int))&C::F)  // Note missing staticmethod call!
  .def("F", (void (C::*)(double))&C::F).staticmethod("F")
;

Tags: of方法defstaticpublicclassintdouble