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

Faheem Mitha faheem at email.unc.edu
Sat Aug 6 19:10:30 CEST 2005


Hi,

Consider wrapping a class containg a virtual function returning
void. The current method, which appears below for convenience, and is
copied verbatim from the tutorial, seems to expect that the virtual
function returns something. In other words, changing f to return void
would break the code.

Is this the case, or am I missing something? Please CC me on any
reply. Thanks.

                                                            Faheem.

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

struct Base
{
    virtual ~Base() {}
    virtual int f() { return 0; }
};

struct BaseWrap : Base, wrapper<Base>
{
    int f()
    {
        if (override f = this->get_override("f"))
            return f(); // *note*
        return Base::f();
    }

    int default_f() { return this->Base::f(); }
};

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




More information about the Cplusplus-sig mailing list