Boost logo

Boost Users :

From: Jacek Generowicz (yg-boost-users_at_[hidden])
Date: 2002-07-23 09:48:33


Hi,

I'm trying to use Boost.Python to create an extension module based on
some existing code. Therein I have a class hierarchy which I would
like to expose in a way that would make it possible to subclass any of
its classes in python. I run into a problem when I try to expose C++
functions which return pointers to the base class of the hierarchy.

In the minimal example I am using for testing purposes I have:

  // An abstract base class
  class abstract {
    ...
    virtual void thing() const = 0;
  };
  
  // A conctrete subclass implemented in C++
  class concrete : public abstract {
    ...
    virtual void thing const { ... }
  };
  
  // Callback to allow happy subclassing of abstract in python
  class abstract_callback : public abstract { ... };
  
  // Callback to allow happy subclassing of concrete in python
  class concrete_callback : public abstract { ... };
  
  
  BOOST_PYTHON_MODULE_INIT(abstract) {
    ...
    python::class_builder<abstract, abstract_callback>
      abs_class(this_module, "abstract");
    ...
    python::class_builder<concrete, concrete_callback>
      con_class(this_module, "concrete");
    con_class.declare_base(abs_class);
    ...
  }

This all works fine, until I try to expose to python a function such
as

  abstract* ret_p_abs( ... );

When compiling (gcc 2.95.2) the module, I get the error

  no matching function for call to `py_extension_class_converters
  (boost::python::type<abstract *>)'

I infer from comments in the source code that this is to be expected
if the class in question has not been wrapped as an extension
class. This makes sense, as abstract has, indeed, not been wrapped
... but I don't think that it should be; abstract_callback was created
for that purpose.

How should I proceed ?

Thanks,


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net