2011-04-20 63 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++。