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

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


Alex Mohr wrote:
>> 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.
> 
> Sure, but then can I replace the registration that boost.python has for 
> the type that I wrapped with my new class?  To be a bit more concrete:
> 
> class_<Foo, bases<Bar> >(...);
> 
> // Build a new python class that derives from the python class for Foo
> // that boost.python generated AND derives from another Python class.

OK.

> // Now I need to replace boost.python's notion of the python class
> // associated with Foo to be the multiply-derived python class I just
> // made.

Why ?

>> 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.
> 
> Well, but you do make it derive from bases other than 'object' by 
> supplying bases<X, Y, Z> -- boost.python looks up python classes 
> associated with X, Y, and Z, and derives the new python wrapper class 
> from those python bases.

Sure. But all these bases get exposed to python the same way, using
the very same metaclass.

> The problem is that I can only specify bases 
> with compile-time type template parameters -- I can't pass arbitrary 
> python classes.

Indeed. I was talking about multiple inheritance within python,
not by means of bases<...>. Sorry if that wasn't clear.

Regards,
		Stefan

-- 

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



More information about the Cplusplus-sig mailing list