[C++-sig] Problems using wrapper.hpp to override virtual functions

Roman Yakovenko roman.yakovenko at gmail.com
Fri Jan 18 21:21:10 CET 2008


On Jan 18, 2008 10:12 PM, Tim Spens <t_spens at yahoo.com> wrote:
> Here is a complete simple example that shows the same error.
>
> #include <boost/python.hpp>
> #include <boost/python/module.hpp>
> #include <boost/python/class.hpp>
> #include <boost/python/wrapper.hpp>
> #include <boost/python/call.hpp>
> using namespace boost::python;
>
> // Class with one pure virtual function
> struct P {
>     virtual ~P(){}
>     virtual char const* f() = 0;
>     char const* g() { return "P::g()"; }
> };
>
> struct PCallback : P, wrapper<P> {
>     char const* f() {
>         return this->get_override("f")();
>     }
> };
>
> // Class with one non-pure virtual function
> struct A {
>     virtual ~A(){}
>     virtual char const* f() { return "A::f()"; }
> };
>
> struct ACallback :  A, wrapper<A> {
>     char const* f() {
>         if (override f = this->get_override("f"))
>             return f();
>         return A::f();
>     }
>     char const* default_f() { return this->A::f(); }
> };
>
> int main() { return 0; }
>
> BOOST_PYTHON_MODULE_INIT(callback) {
>     class_<PCallback,boost::noncopyable>("P")
>         .def("f", boost::python::pure_virtual(&P::f));
>     class_<ACallback,boost::noncopyable>("A")
>         .def("f", &A::f, &ACallback::default_f);
> }
>
> >>> import callback
> >>> b = callback.P()
> >>> class derived(b):

Is this intentional to create Python class that derived from variable?
I guess you wanted to write
class derived( callback.P ):

Am I right?

-- 
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/



More information about the Cplusplus-sig mailing list