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: tue...@cbs.mpg.de
www.cbs.mpg.de

_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to