如何使用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: 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")
;
请邮寄正被抛出的异常。 – 2012-01-03 16:51:08
@ChristianJonassen:编辑。 – 2012-01-03 16:53:30