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

Alex Mohr amohr at pixar.com
Wed Nov 1 20:26:08 CET 2006


>> 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 ?

So that when boost.python converts a Foo to-python it generates a 
wrapper that derives from the extra class that I want it to.  Also, so 
when someone invokes Foo's constructor in python, they get an object 
that has the bases I desire.

I mean, I really want the wrapper for Foo to derive from this other 
Python class.

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

Sure, but in some sense it's the same thing -- when I say class_<Foo>, 
boost.python just uses the python C api to build a wrapper class (which 
derives from the wrapper classes for the types I specified in bases<>). 
  I just want to provide an extra base class.

Alex



More information about the Cplusplus-sig mailing list