[C++-sig] [boost.python] Exposing abstract derived classes
Maximilian Matthe
Maxi.Matthe at web.de
Mon Jul 14 21:04:53 CEST 2008
Hi!
I have a problem with exposing derived classes to python:
class Base
{
public:
virtual void f() = 0;
}
class Derived : public Base
{
public:
virtual void g() = 0;
}
// here's how to wrap and expose Base:
class BaseWrap : public Base, public wrapper<Base>
{
public:
void f()
{
this->get_override("f")();
}
}
BOOST_PYTHON_MODULE(a)
{
class_<BaseWrap, boost::noncopyable>("Base")
.def(f, pure_virtual(&BaseWrap::f)) ;
}
// How should I wrap and expose Derived?
// It is also pure virtual, but if I create a wrapper that
// derives from Derived and wrapper<Derived> and create the method
// g(), f() is still not implmented, thus it does not compile.
I do not feel comfortable by deriving DerivedWrapper from BaseWrapper,
Derived and wrapper<Derived>, which could even not work because of
same base classes and so on.
So what is the right implementation for my problem?
Regards, Max
More information about the Cplusplus-sig
mailing list