2011-04-20 61 views
1

我无法理解用boost.python将某些函数导出为python的正确方法。模板导出问题

我已经出口这个类CL_Rectf。它继承了CL_Rectx<float>

现在我想导出功能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导出有问题。怎么了?

回答

1

尤其不知道Boost.Python,在我看来,您导出CL_Rectf,但不是CL_Rectx<float>。因此,当被要求将python对象转换为CL_Rectx<float>时,Boost.Python不知道如何,并引发了您看到的异常。

我的建议是忘记CL_Floatf并导出CL_Rectx<float>类。作为C++类的CL_Rectf在如此多的层次上是一个糟糕的主意;你应该尽量避免使用C++。