[C++-sig] Supplying a Python base class when wrapping a C++ class...

Stefan Seefeld seefeld at sympatico.ca
Wed Nov 1 19:22:31 CET 2006


Alex Mohr wrote:
> I'd like to wrap a C++ class and have the generated python wrapper class 
> derive from a Python class.
> 
> I know I can use bases<> to have my wrapped class derive from the class 
> objects associated with the C++ types I specify in bases<>, but in this 
> instance, I want to derive my wrapper class from a Python class that was 
> not generated by boost.python.
> 
>  From looking at the code, it seems like it would be some work to add 
> this capability.  (Is anyone working on something like this?)
> 
> As a workaround, does anyone know a way that I could perhaps hack this 
> in after the Python class is created?  That is, can I change the Python 
> base classes of a Python class at runtime?

I believe this depends on what you are trying to accomplish. You can
certainly derive a new python class from both, the python wrapper for
your C++ class, as well as some other python class.

I don't think it's possible to make the generated wrapper itself be
derived from a particular python base class (other than 'object').
This is because all wrappers have a common metaclass, provided by boost.python,
and python puts some constraints on the relationship between metaclasses
of derived types.

But multiple inheritance should be able to help.

Regards,
		Stefan

-- 

      ...ich hab' noch einen Koffer in Berlin...



More information about the Cplusplus-sig mailing list