[C++-sig] Re: [boost-python] overloading problem

David Abrahams dave at boost-consulting.com
Fri Apr 9 01:51:16 CEST 2004


"Neal D. Becker" <ndbecker2 at verizon.net> writes:

> I'm having trouble with overloading.  It seems to work for default args, but
> not for a family of fncs with common prefix.  

Yes, it seems we have another instance of untested code in the
tutorial here.  Joel, can you fix that, please?

> This is on gcc-3.3.3.
>
> #include <boost/python/module.hpp>
> #include <boost/python/def.hpp>
> #include <boost/python/class.hpp>
> #include <boost/python/init.hpp>
> #include <boost/python/overloads.hpp>
>
> using namespace boost::python;
>
> struct george
> {
>   void wack_em(int a) {}
>   void wack_em(int a, int b) {}
> };
>
> BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(george_overloads, wack_em, 1, 2)

I'd probably call it "wack_em_overloads" instead, but that's an
aesthetic issue.

>   BOOST_PYTHON_MODULE (GEORGE) {
>   class_<george> ("george")
>     .def("wack_em", &george::wack_em, george_overloads())

Should be:

     .def("wack_em", (void(george::*)(int,int))0, george_overloads())

Actually, it occurs to me that since we know the maximum number of
arguments, there's might be a way to make your code work as-is using
template argument deduction... but I think it would be a giant mess
'o' metaprogramming for only a tiny gain.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com





More information about the Cplusplus-sig mailing list