[C++-sig] deriving in python from a C++ base class

Stefan Seefeld seefeld at sympatico.ca
Wed Jul 2 03:57:23 CEST 2003


hi there,

I have trouble extending a demo from the tutorial (taken from
http://www.boost.org/libs/python/doc/tutorial/doc/exposing_classes.html).

Instead of just instantiating objects of type 'World' in python, I
subclass 'World' first, making calls to base class methods from the
constructor:

class MyWorld(World):
     def __init__(self):
         self.set('hi there')
         print self.greet()

that ought to be possible (or so I thought), but instantiating a 'MyWorld'
object (still inside python) yields:

Traceback (most recent call last):
   File "test.py", line 18, in ?
     world = MyWorld()
   File "test.py", line 10, in __init__
     self.set('hi there')
TypeError: bad argument type for built-in operation

Reading on in the tutorial I find some information about polymorphism on

http://www.boost.org/libs/python/doc/tutorial/doc/class_virtual_functions.html,

but that page explicitely states that the use of auxiliary wrapper classes
is only needed in case I want to access the virtual (python overridden) methods
from within C++, which is not (yet) my case, i.e. as far as I'm aware of in my
little test there isn't any form of polymorphism involved.

What am I missing ?

Thanks,
		Stefan





More information about the Cplusplus-sig mailing list