[C++-sig] Calling overidden pure virtual function from C++ side

Roman Yakovenko roman.yakovenko at gmail.com
Thu Aug 21 20:01:27 CEST 2008


2008/8/21 william marié <william.marie at gmail.com>:
> Hi,
>
> It's already done sorry, i didn't write the __init__ function in the post :
>     def __init__( self ) :
>           dum.A.__init__( self )
>
> Even with that it's not working, can we normally call virtual function from
> the C++ side ?

Here is an exercise for you: find the difference between your code and
the one, that were generated by Py++:

#include "boost/python.hpp"

#include "1.h"

namespace bp = boost::python;

struct A_wrapper : A, bp::wrapper< A > {

    A_wrapper()
    : A()
      , bp::wrapper< A >(){
        // null constructor

    }

    virtual void foo(  ){
        bp::override func_foo = this->get_override( "foo" );
        func_foo(  );
    }

};

BOOST_PYTHON_MODULE(pyplusplus){
    bp::class_< A_wrapper, boost::noncopyable >( "A" )
        .def(
            "bar"
            , (void ( ::A::* )(  ) )( &::A::bar ) )
        .def(
            "foo"
            , bp::pure_virtual( (void ( ::A::* )(  ) )(&::A::foo) ) );
}

P.S. Next time try to post example, which contains "the whole picture".

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



More information about the Cplusplus-sig mailing list