[C++-sig] wrapping virtual function returning void

Faheem Mitha faheem at email.unc.edu
Sun Aug 7 04:38:25 CEST 2005



On Sat, 6 Aug 2005, Eric Jardim wrote:

> That's easy!
>
> struct BaseWrap : Base, wrapper<Base>
> {
> void f()
> {
> if (override f = this->get_override("f"))
> f();
> else
> Base::f();
> }
>
> void default_f() { Base::f(); }
> };

That's interesting. So, for pure virtual functions, it would look like the 
version below?

I don't understand what this wrapper is doing, so that makes it more 
difficult for me to make these deductions.

According to the documentation, it overrides the base class in Python. I 
assume this is related to the derived class wrappers in Python knowing of 
their derived relationship to the base class wrapper, but I'm pretty fuzzy 
on the details.

If some kind person wants to try to explain it, I'm all ears.

                                                                  Faheeem.
*************************************************************************
#include <boost/python.hpp>
using namespace boost::python;

struct Base
{
     virtual ~Base() {}
     virtual void f() = 0;
};

struct BaseWrap : Base, wrapper<Base>
{
   void f()
   {
     this->get_override("f")();
   }
};

BOOST_PYTHON_MODULE(hello)
{
   boost::python::class_<BaseWrap, boost::noncopyable>("Base")
     .def("f", boost::python::pure_virtual(&Base::f))
     ;
}




More information about the Cplusplus-sig mailing list