Closed shelllet closed 10 months ago
class Strs { std::vector<Str> m_cc; public: ... Str [](int offset) { return m_cc[offset];} ... }; class Str{}; struct StrToPython { static PyObject* convert(const Str& b) { ... } }; BOOST_PYTHON_MODULE(pytype_function_ext) { class_<Strs >("Strs") ; to_python_converter< Str , StrToPython>(); }
py::object list(Strs());
py::object s1 = list[0];// (1), throw "No Python class registered for C++ class Str"
py::object s2(Str()) // ok!it's call StrToPython::convert.
StrToPython::convert
becuase to_python_converter does't set m_class_object value. so (1) throw errors.
to_python_converter
m_class_object
how to resolve this problem?
By default indexed elements are returned by proxy. disabled by supplying true in the NoProxy template parameter.
test code
py::object list(Strs());
py::object s1 = list[0];// (1), throw "No Python class registered for C++ class Str"
py::object s2(Str()) // ok!it's call
StrToPython::convert
.becuase
to_python_converter
does't setm_class_object
value. so (1) throw errors.how to resolve this problem?