Max Frai
Max Frai

Reputation: 64276

Template export troubles

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?

Upvotes: 1

Views: 147

Answers (1)

Marc Mutz - mmutz
Marc Mutz - mmutz

Reputation: 25293

Without knowing Boost.Python in particular, it seems to me that you exported CL_Rectf, but not CL_Rectx<float>. So when asked to convert a python object into a CL_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 the CL_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++.

Upvotes: 1

Related Questions