[C++-sig] Overloaded pure virtual method
Roman Yakovenko
roman.yakovenko at gmail.com
Tue Oct 24 21:58:36 CEST 2006
On 10/24/06, Mark Williams <mark at image-engine.com> wrote:
>
> Hi, I'm having some difficulty understanding the syntax for binding pure virtual member functions with default arguments. Here
> is a simple class definition:
>
> class TestOverloads
> {
> public:
> virtual ~TestOverloads() {}
> virtual void overloaded(float f = 0) =0;
>
> };
>
> I have also defined:
>
> BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(MyOverloads, overloaded, 0, 1);
This macro should not be used for pure virtual functions.
> What am I doing wrong here, please?
You should use boost::python::arg to add default value.
http://boost.org/libs/python/doc/v2/args.html
Next code was generated by Py++:
struct TestOverloads_wrapper : TestOverloads, bp::wrapper< TestOverloads > {
TestOverloads_wrapper()
: TestOverloads()
, bp::wrapper< TestOverloads >(){
// null constructor
}
virtual void overloaded( float f=0 ){
bp::override func_overloaded = this->get_override( "overloaded" );
func_overloaded( f );
}
};
BOOST_PYTHON_MODULE(pyplusplus){
bp::class_< TestOverloads_wrapper, boost::noncopyable >(
"TestOverloads" )
.def(
"overloaded"
, bp::pure_virtual( &::TestOverloads::overloaded )
, ( bp::arg("f")=0 ) );
}
This code allows you to create new classes in Python that derives from
TestOverloads class.
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
More information about the Cplusplus-sig
mailing list