Boost logo

Boost Users :

From: Bruce Lowery bruce_lowery_at_[hidden])
Date: 2003-01-14 11:35:55


<bruce_lowery_at_y...>" <bruce_lowery_at_y...> wrote:
>
> Using Boost/Python, how does one overload methods? For instance:
>
> struct Bar
> {
> void func( const std::string& s );
> void func( int i );
> };
>
> BOOST_PYTHON_MODULE( Foo )
> {
> class_<Bar>( "Bar" )
> .def( "func", &Bar::func )
> .def( ??? )
> ;
> }
>
> The reference documentation discusses the
> BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS macro, but it only seems to
> apply to methods with default arguments.
>
> --bruce

I should have scanned the python c++ SIG first. Also now realize
that python.boost questions are preferred on that list rather than
here.

For future newbie reference, solution to above appears to be:

struct Bar
{
     void func( const std::string& s );
     void func( int i );
};

BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( Bar_func_overloads,
Bar::func, 1, 1 )

BOOST_PYTHON_MODULE( Foo )
{
class_<Bar>( "Bar" )
.def("func",(void(Bar::*)(const std::string&))0,Bar_func_overloads)
.def("func",(void(Bar::*)(int))0,Bar_func_overloads)
;
}

--bruce


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net