[boost.python] "Thin wrappers" for member functions
It's possible to expose free functions through "thin wrappers": void f() { //... } void f_wrapper() { // ... some extra functionality to be done when called from Python only f(); } def("f", f_wrapper); But is it possible to write "thin wrappers" for member functions (without modifying the wrapped class)? struct foo { void f(); }; // f_wrapper defined somehow somewhere class_<foo>("foo") .def("f", f_wrapper???) Thanks, Marcin
on Sat Jul 21 2007, "Marcin Kalicinski"
It's possible to expose free functions through "thin wrappers":
void f() { //... }
void f_wrapper() { // ... some extra functionality to be done when called from Python only f(); }
def("f", f_wrapper);
But is it possible to write "thin wrappers" for member functions (without modifying the wrapped class)?
struct foo { void f(); };
// f_wrapper defined somehow somewhere
class_<foo>("foo") .def("f", f_wrapper???)
Yeah, just use a non-const reference to the class type as the first argument to a free function. void f_wrapper(foo&, int); class_<foo>("foo") .def("f", f_wrapper???) ====== >>> foo.f(3) >>> -- Dave Abrahams Boost Consulting http://www.boost-consulting.com The Astoria Seminar ==> http://www.astoriaseminar.com
participants (2)
-
David Abrahams
-
Marcin Kalicinski