Boost.Python 静态方法重载
如何使用 Boost.Python 公开以下类?
class C {
public:
static void F(int) {}
static void F(double) {}
};
我尝试了这样的事情:
bp::class_<C>("C")
.def("F", (void (C::*)(int))&C::F).staticmethod("F")
.def("F", (void (C::*)(double))&C::F).staticmethod("F")
;
但是,它在 Python 中引发了一个异常(SystemError:libdistributions 的初始化引发了未报告的异常
)。如果我从 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")
;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为在这里您可以找到问题的解决方案:
http://www.boost.org/doc/libs/1_48_0/libs/python/doc/tutorial/doc/html/python/functions.html#python.overloading
I think here you can find the solution to your problem:
http://www.boost.org/doc/libs/1_48_0/libs/python/doc/tutorial/doc/html/python/functions.html#python.overloading