[C++-sig] wrapping abstract classes question
David Abrahams
dave at boost-consulting.com
Sun Dec 4 15:37:15 CET 2005
Roman Yakovenko <roman.yakovenko at gmail.com> writes:
> The are 2 approaches to create wrapper for derived class
> 1.
>
> struct derived_wrapper
> : derived, boost::python::wrapper< derived >{
>
> virtual int do_smth( ){
> boost::python::override do_smth = this->get_override( "do_smth" );
> return do_smth( );
> }
>
> virtual int do_smth_else( ){
> boost::python::override do_smth_else = this->get_override(
> "do_smth_else" );
> return do_smth_else( );
> }
>
> }
>
> 2.
>
> struct derived_wrapper : derived, base_wrapper,
> boost::python::wrapper< derived >{
>
> virtual int do_smth_else( ){
> boost::python::override do_smth_else = this->get_override(
> "do_smth_else" );
> return do_smth_else( );
> }
>
> }
>
> It seems to me that both approaches will work, but I do not know which
> one is better
> ( right ) and which one is not.
This one is tricky. I think this is probably the best you can do.
template <class B>
struct wrap_base : B
{
int do_smth()
{
return this->get_override("do_smth")();
};
};
struct base_wrapper
: wrap_base<base>, boost::python::wrapper<base>
{
};
struct derived_wrapper
: wrap_base<derived>, boost::python::wrapper<derived>
{
int do_smth_else()
{
return this->get_override("do_smth_else")();
};
};
HTH,
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list