[C++-sig] Member function bp::optional? Or workaround?

troy d. straszheim troy at resophonic.com
Tue Jan 12 21:01:53 CET 2010


Charles Solar wrote:
> Well I want to define the overloads myself anyway, I just do not know 
> how to properly setup the small wrapper that will work.  In the doc it 
> tells you how to make flat function wrappers, but nothing on member 
> function wrappers.  I am unsure how I am supposed to handle the this 
> pointer, for example.
> So idealy what I would like to know is what the macro does so I can 
> manually write out the wrappers myself.
> 
> And I have tried using Py++, it does not handle the default argument, it 
> just puts the call in there and python still requires the param to be there.
> 

Personally I hate that overload-wrapping macro thing.  Here's one way to 
do it:

struct T
{
   void bar(int i) { cout << "bar(" << i << ")\n"; }
   void bar() { cout << "bar\n"; }
};

//
// use 'self' for 'this' for the sake of pythonicism
//
void bar_int (T* self, int i) { self->bar(i); }
void bar_void(T* self)        { self->bar();  }

BOOST_PYTHON_MODULE(foop)
{
   class_<T>("T")
     .def("bar", bar_int)
     .def("bar", bar_void)
     ;
}

-t



More information about the Cplusplus-sig mailing list