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

Stefan Seefeld seefeld at sympatico.ca
Tue Jun 24 22:23:54 CEST 2008


Carsten Harms wrote:
> 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.
>

I think you need to establish the parent/child relationship also at 
runtime, through explicit constructor calls:

class TestState2(GameStateBase, KeyListener):

    def __init__(self):
        super(TestState2, self).__init__()

    ....


I'm not sure why the single inheritance works, it should suffer the same 
problem.


HTH,
       Stefan

-- 

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




More information about the Cplusplus-sig mailing list