模板导出问题
我无法理解使用 boost.python 将某些函数导出到 python 的正确方法。
我已经导出了这个类CL_Rectf。它继承CL_Rectx
。
现在我想导出函数 bounding_rect
:
# In CL_Rectf class exporting
.def("BoundingRect", &CL_Rectf::bounding_rect, PYPOLICY_REFERENCE_EXISTING)
它可以编译,但是当我在 python 中使用此代码时:
mBox = CL_Rectf()
mBox.BoundingRect(CL_Rectf(x, y, x2, y2))
我遇到这样的错误:
Boost.Python.ArgumentError: Python argument types in
CL_Rectf.BoundingRect(CL_Rectf, CL_Rectf)
did not match C++ signature:
BoundingRect(CL_Rectf {lvalue}, CL_Rectx<float>)
由于 c++ 签名中的 CL_Rectx
导致导出出现问题。怎么了?
I can't understand the right way for exporting some function into python with boost.python.
I have exported this class CL_Rectf. It inherits CL_Rectx<float>
.
Now I want to export function bounding_rect
:
# In CL_Rectf class exporting
.def("BoundingRect", &CL_Rectf::bounding_rect, PYPOLICY_REFERENCE_EXISTING)
It compiles, but when I use this code in python:
mBox = CL_Rectf()
mBox.BoundingRect(CL_Rectf(x, y, x2, y2))
I have such error:
Boost.Python.ArgumentError: Python argument types in
CL_Rectf.BoundingRect(CL_Rectf, CL_Rectf)
did not match C++ signature:
BoundingRect(CL_Rectf {lvalue}, CL_Rectx<float>)
Something wrong with exporting due to CL_Rectx
in c++ signature. What's wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在不特别了解 Boost.Python 的情况下,在我看来,您导出了
CL_Rectf
,但没有导出CL_Rectx
。因此,当要求将 python 对象转换为CL_Rectx
时,Boost.Python 不知道如何转换,并引发您看到的异常。我的建议是忘记
CL_Floatf
并导出CL_Rectx
类。CL_Rectf
作为 C++ 类在很多层面上都是一个坏主意;即使在 C++ 中,你也应该尽量避免使用它。Without knowing Boost.Python in particular, it seems to me that you exported
CL_Rectf
, but notCL_Rectx<float>
. So when asked to convert a python object into aCL_Rectx<float>
, Boost.Python doesn't know how, and raises the exception you see.My advice would be be to forget about
CL_Floatf
and export theCL_Rectx<float>
class instead.CL_Rectf
as a C++ class is a bad idea on so many levels; you should try to avoid its use even in C++.