[C++-sig] .def & virtual functions with default implementations

Matthias Baas baas at ira.uka.de
Fri Apr 16 17:01:04 CEST 2004


Hi,

in the tutorial there's an example how to wrap virtual methods that have 
default implementations 
(http://www.boost.org/libs/python/doc/tutorial/doc/virtual_functions_with_default_implementations.html).
I think I've understood the principle, however I don't quite understand 
this line:

  .def("f", &Base::f, &BaseWrap::default_f)

Why do I have to provide &Base::f? Why isn't it enough to write

   .def("f", &BaseWrap::default_f)

This would already have the effect that calling f() from Python will 
actually call the default implementation instead of recursively calling 
the dispatch function. And when f() is called from C++ the dispatch 
function will be called because it overrides the original function. If 
all this is correct, then why does Boost.Python need to know about &Base::f?

Actually, this latter approach is used in the example in the Wiki which 
looks like this:

   .def("greet", &hello_callback::default_greet);

(http://www.python.org/cgi-bin/moinmoin/boost_2epython_2fOverridableVirtualFunctions)

So what is actually the difference of those two types of definitions? 
And which tutorial is correct?

- Matthias -





More information about the Cplusplus-sig mailing list