0

I am trying to create an object using boost python. The class definition (pseudocode):

class Awrap : public A, public boost::python::wrapper<A> {
   static std::shared_ptr<A > Create(...) { ... } // inherited from A

   virtual double foo(...) override { // overrides pure virtual function in A
          return this->get_override("foo")(...);
   }
};

BOOST_PYTHON_MODULE() {
   using namespace boost::python
   class_<Awrap,std::shared_ptr<Awrap>, boost::noncopyable>("A",boost::python::no_init)
     .def("Create",&A::Create).staticmethod("Create")
     .def("foo",pure_virtual(&Awrap::foo));

     boost::python::register_ptr_to_python<std::shared_ptr<A> >();
}

The problem is that when I implement the child in python and call the static create method it creates a pointer to Awrap (not the child). So it cannot find the python-implemented version of "foo". If I implement foo in the Awrap class instead of the python child it works fine, but I don't want to do this!

Any suggestions?

Thanks!

ad_ad
  • 375
  • 3
  • 14

1 Answers1

0

You need to expose both Awrap::foo and A::foo to boost python. See example in:

http://www.boost.org/doc/libs/1_54_0/libs/python/doc/tutorial/doc/html/python/exposing.html

shoosh
  • 76,898
  • 55
  • 205
  • 325