[C++-sig] problem with boost::python::extract of c++ pointers from objects with multiple inheritance

Carsten Harms CarstenHarms9368 at gmx.de
Tue Jun 24 21:57:04 CEST 2008


Hi!

I'm trying to extract a C++ pointer from a boost::python::object which 
inherited two base classes (both python extensions).
I'm using boost 1.35 under MSVC 9.

KeyListener exposing:
>     class_<KeyListenerWrap, boost::noncopyable>("KeyListener" )
>         .def("keyPressed", 
> pure_virtual(&OIS::KeyListener::keyPressed), 
> return_value_policy<return_by_value>() )
>         .def("keyReleased", 
> pure_virtual(&OIS::KeyListener::keyReleased), 
> return_value_policy<return_by_value>() )
>         ;
GameState exposing:
>     class_<GameStateBaseWrap, boost::noncopyable>("GameStateBase" )
>         .def("enter", pure_virtual(&GameStateBase::enter))
>         .def("exit", pure_virtual(&GameStateBase::exit))
>         .def("pause", &GameStateBase::pause, &GameStateBaseWrap::pause)
>         .def("resume", &GameStateBase::resume, &GameStateBaseWrap::resume)
>         .def("frameStarted", 
> pure_virtual(&GameStateBaseWrap::frameStarted), 
> return_value_policy<return_by_value>() )
>         .def("frameEnded", 
> pure_virtual(&GameStateBaseWrap::frameEnded), 
> return_value_policy<return_by_value>() )
>         ;
Please note that both c++ bases can be extracted as pointers when only 
_1_ is used as a base.
for example:
> class TestKeyListener(KeyListener):
>     def keyPressed(self, kevt):
>         print "key pressed:"
>         return True
>         
>     def keyReleased(self, kevt):
>         print "key released:"
>         return True
> class TestState(GameStateBase):
>     def enter(self):
>         print "enter!"
>     def exit(self):
>         print "exit!"
work as expected. I can extract the c++ pointer to their c++ base with
> extract<OIS::KeyListener*> (_obj);
or
> extract<GameStateBase*> (_obj);
But as soon as I inherit both like
> class TestState2(GameStateBase, KeyListener):
>     def enter(self):
>         print "enter!"
>     def exit(self):
>         print "exit!"
>
>     def keyPressed(self, kevt):
>         print "key pressed:"
>         return True
>
>     def keyReleased(self, kevt):
>         print "key released:"
>         return True
I can only extract the first base, GameStateBase in this example. If I 
exchange GameStateBase and KeyListener, I can only extract KeyListener. 
This is the error which I'm getting:
> TypeError: No registered converter was able to extract a C++ pointer 
> to type class OIS::KeyListener from this Python object of type TestState2
Well, can someone tell me if I made a mistake, if this is a bug of 
boost::python, or if it just isn't implemented yet.

Thanks in advance
Carsten Harms





More information about the Cplusplus-sig mailing list