[C++-sig] Inheritance question

Koen Van Herck koen_van_herck at yahoo.com
Fri Feb 10 14:58:05 CET 2006


Stefan Seefeld wrote:
>
> Koen Van Herck wrote:
> > Hello,
> >
> > I want to expose the following classes in Python:
> >
> > class Base
> > {
> > public:
> >     virtual void f() = 0;
> > };
> >
> > class Derived: public Base
> > {
> > public:
> >     void f() { std::cout << "Derived::f" << std::endl; }
> >     void g() { std::cout << "Derived::g" << std::endl; }
> > };
> >
> > class User
> > {
> > public:
> >     void useBase(Base & b) { b.f(); }
> > };
> >
> > I've created the following code in my BOOST_PYTHON_MODULE
> >
> >     class_<User>("User")
> >         .def("useBase", &User::useBase)
> >     ;
> >
> >     class_<Derived>("Derived")
> >         .def("g", &Derived::g)
> >     ;
>
> This should be class_<Derived, bases<Base> > ...

Doesn't work, because I have not exposed Base.
I do expose Base, using a BaseWrap class as follows:

class BaseWrap: public Base, public wrapper<Base>
{
public:
    void f()
    {
        this->get_override("f")();
    }
};

But this does not let me use bases<Base>. I get the following error when
importing my module:

RuntimeError: extension class wrapper for base class class Base has not been
created yet





More information about the Cplusplus-sig mailing list