c++ - How to wrap with boost-python a virtual class with a method returning a reference -
c++ - How to wrap with boost-python a virtual class with a method returning a reference -
i have 2 virtual classes wrap in boost python, want able write python class extends them. thing is, 1 of classes has method homecoming reference of other class, , can't figure how do.
here simplified version of code of class wrapped.
class foo { public: virtual ~foo() {} virtual int a() = 0; }; class bar { public: virtual ~bar() {} virtual foo const& b() = 0; };
so started wrapping way.
class foowrap : public foo, public wrapper<foo> { public: int a() { homecoming this->get_override("a")(); } }; class barwrap : public bar, public wrapper<bar> { public: foo const& b() { homecoming this->get_override("b")(); } }; boost_python_module(foobar) { class_<foowrap, boost::noncopyable>("foo") .def("a", pure_virtual(&foo::a)) ; class_<barwrap, boost::noncopyable>("bar") .def("b", pure_virtual(&bar::b)) ; }
and compile error "cannot instantiate abstract class [...] pure virtual function not defined" "see declaration of 'foo::a'"
i've been able compile , run code after added phone call policy bar::b
function:
boost_python_module(foobar) { class_<foowrap, boost::noncopyable>("foo") .def("a", pure_virtual(&foo::a)); class_<barwrap, boost::noncopyable>("bar") .def("b", pure_virtual(&bar::b), return_internal_reference<>()); }
basically, it's means lifetime of returned reference bar::b
should dependent on lifetime of bar
instance. can read phone call policies in boost docs.
what compiler , boost version using? i've got next descriptive error boost 1.46.0 , gcc 4.6.1:
error: no match phone call ‘(const boost::python::detail::specify_a_return_value_policy_to_wrap_functions_returning<const foo&>) (const foo&)’
c++ python boost-python
Comments
Post a Comment