【发布时间】:2018-12-05 16:58:28
【问题描述】:
我正在尝试使用 boost python 将具有名称别名的 C++ 类公开给 python。
struct Foo
{
void hi() const { std::cout << "hi" << std::endl; }
};
BOOST_PYTHON_MODULE(Example)
{
typedef Foo Bar;
class_<Foo>("Foo")
.def("hi", &Foo::hi)
;
class_<Bar>("Bar")
.def("hi", &Bar::hi)
;
}
除了烦人的 RuntimeWarning 之外,代码按预期工作。
RuntimeWarning: to-Python converter for Foo already registered; second conversion method ignore
在 python 中添加Bar = Foo 也可以。但我需要将定义保留在同一个模块中。有没有更好的方法来实现这一点?
【问题讨论】:
标签: python c++ boost-python