Boost.Python静态方法重载

Nei*_*l G 5 c++ python boost-python

如何使用Boost.Python公开以下类?

class C {
 public:
  static void F(int) {}
  static void F(double) {}
};
Run Code Online (Sandbox Code Playgroud)

我试过这样的事情:

bp::class_<C>("C")
  .def("F", (void (C::*)(int))&C::F).staticmethod("F")
  .def("F", (void (C::*)(double))&C::F).staticmethod("F")
;
Run Code Online (Sandbox Code Playgroud)

但是,它在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")
;
Run Code Online (Sandbox Code Playgroud)