[C++-sig] Inheritance problem

Erik Türke tuerke at cbs.mpg.de
Thu Oct 13 17:34:00 CEST 2011


Hi all,

currently i am facing a problem regarding inheritance with boost::python

Here is a simple code snippet:


class Base
{
public:
     virtual void print() { std::cout << "hello" << std::endl; }

};


class BaseWrapper : public Base, public wrapper<Base>
{
public:
BaseWrapper( PyObject *p ) : self(p) {}
BaseWrapper( PyObject *p, const Base &base) : Base(base), wrapper< Base 
 >(), self(p) {}

     virtual void _print() { print(); }

private:
     PyObject const *self;
};

class Derived : public Base
{
public:
     Derived() {}
     Derived( PyObject *p ) : self(p){}
private:
     PyObject const *self;
};

BOOST_PYTHON_MODULE( my_module )
{

     class_<Base, BaseWrapper>( "Base", init<>() )
     .def("printIt", &BaseWrapper::_print)
     ;
     class_<Derived, bases<Base> >( "Derived", init<>() );
}

And in python i want to have the following reslut:

 >>import my_module
 >> derived = my_module.Derived()
 >> derived.printIt()

Actually this should print "hello" but instead throws an error saying:

derived.printIt()
Boost.Python.ArgumentError: Python argument types in
Base.printIt(Derived)
did not match C++ signature:
     printIt(_Base {lvalue})

I tried a lot of modification but always getting this message.
Does somebody of you know what i am missing?

Thanks a lot in advance!

Best regards!

-- 
Erik Türke
Department of Neurophysics
Max-Planck-Institute for Human Cognitive and Brain Sciences
Stephanstrasse 1A
04103 Leipzig
Germany
Tel: +49 341 99 40-2440
Email: tuerke at cbs.mpg.de
www.cbs.mpg.de



More information about the Cplusplus-sig mailing list